How to get text value from string ArrayAdapter in ListView?

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.

Answers


change the line

String itemname = new Integer(position).toString();

to this

String itemname = lv_arr[position];

Change your itemname declaration to this.

String itemname = ((TextView) findViewById(R.id.app_name)).getText().toString();

Need Your Help

Render plaintext using Angular route, ui-view

angularjs angular-ui-router plaintext

I am using Angular 1.3, creating views using ui-router and ui-view.

C# serialPort speed

c# .net performance serial-port

I am developing some monitoring tool for some kind of protocol based on serial communication.