darkhah1
یک شنبه 23 آذر 1393, 08:27 صبح
با سلام خدمت اساتید
من واسه سرچ در متن از کد زیر استفاده کردم ولی این کد فقط برای یک تکست ویو است من در یک صحفه خود حدود 15 تکست ویو دارم
کدی می خواستم که برای تمام تکست ویوی یک اکتیویتی استفده بشه
public class MotivationalQuotesActivity extends Activity {
/** Called when the activity is first created. */
Button next;
EditText et;
TextView tv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
et = (EditText) findViewById(R.id.et);
tv = (TextView) findViewById(R.id.tv);
tv.setText("The name of our country is Bangladesh");
next = (Button) findViewById(R.id.button1);
next.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
String ett =et.getText().toString();
String tvt =tv.getText().toString();
int index = tvt.indexOf(ett);
Spannable WordtoSpan = new SpannableString( tv.getText() );
if(index != -1)
{
WordtoSpan.setSpan(new BackgroundColorSpan(0xFFFFFF00), index, index+ett.length(),Spannable.SPAN_EXCLUSIVE_EXCLUS IVE);
tv.setText(WordtoSpan, TextView.BufferType.SPANNABLE);
}
else
tv.setText("The name of our country is Bangladesh");
}
});
}
}
من واسه سرچ در متن از کد زیر استفاده کردم ولی این کد فقط برای یک تکست ویو است من در یک صحفه خود حدود 15 تکست ویو دارم
کدی می خواستم که برای تمام تکست ویوی یک اکتیویتی استفده بشه
public class MotivationalQuotesActivity extends Activity {
/** Called when the activity is first created. */
Button next;
EditText et;
TextView tv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
et = (EditText) findViewById(R.id.et);
tv = (TextView) findViewById(R.id.tv);
tv.setText("The name of our country is Bangladesh");
next = (Button) findViewById(R.id.button1);
next.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
String ett =et.getText().toString();
String tvt =tv.getText().toString();
int index = tvt.indexOf(ett);
Spannable WordtoSpan = new SpannableString( tv.getText() );
if(index != -1)
{
WordtoSpan.setSpan(new BackgroundColorSpan(0xFFFFFF00), index, index+ett.length(),Spannable.SPAN_EXCLUSIVE_EXCLUS IVE);
tv.setText(WordtoSpan, TextView.BufferType.SPANNABLE);
}
else
tv.setText("The name of our country is Bangladesh");
}
});
}
}