Reputation: 4183
I have an app with two activities: 1st - listview with links to html files, second is a webview. For example I press "First Topic" in the listview, it opens "1.html" in the webview. I want to get text value of clicked element in the listview and show it in textview of second activity by this method:
TextView title = (TextView) findViewById(R.id.app_name);
title.setText(getString(R.string.app_name));
Here is a code of ListViewActivity:
public class ListViewActivity extends Activity implements OnClickListener {
private ListView lv1;
private String lv_arr[] = { "First Topic", "Second Topic" };
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.list);
lv1 = (ListView) findViewById(R.id.listView);
lv1.setAdapter(new ArrayAdapter<String>(this, R.layout.list_items,
lv_arr));
lv1.setTextFilterEnabled(true);
lv1.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> a, View v, int position,
long id) {
String itemname = new Integer(position).toString();
Intent intent = new Intent();
intent.setClass(ListViewActivity.this, WebViewActivity.class);
Bundle b = new Bundle();
b.putString("defStrID", itemname);
intent.putExtras(b);
startActivity(intent);
}
});
}
}
How can I pass the value which was clicked in listview to webviewactivity? Help, please.
Upvotes: 2
Views: 5271
Reputation: 342
Change your itemname
declaration to this.
String itemname = ((TextView) findViewById(R.id.app_name)).getText().toString();
Upvotes: 0
Reputation: 68177
change the line
String itemname = new Integer(position).toString();
to this
String itemname = lv_arr[position];
Upvotes: 3