pobieranie łańcucha z elementu listview w setOnItemClickListener

Zastanawiałem się, jak mogę uzyskać ciąg z klikniętego elementu widoku listy. Na przykład mam wpis w tym formacie.

# - John Smith

[email protected]

3451234532

Nowy Jork

Chcę dostać Johna Smitha. Mogę zdobyć przedmiot na tej pozycji, ale nie znam reszty.

Moje kody:

package com.example.deneme;
import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
import android.widget.Toast;


public class Activity2 extends Activity {

private SQLiteAdapter mySQLiteAdapter;
 ListView listContent;
 SimpleCursorAdapter cursorAdapter;
 Cursor cursor;
 Button buttonDeleteAll,buttonDeleteRow;

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.activity2);


buttonDeleteAll = (Button)findViewById(R.id.deleteall);
buttonDeleteRow = (Button)findViewById(R.id.deleterow); 
listContent = (ListView)findViewById(R.id.contentlist);
listContent.setClickable(true);
buttonDeleteAll.setOnClickListener(buttonDeleteAllOnClickListener);
buttonDeleteRow.setOnClickListener(buttonDeleteRowOnClickListener);


mySQLiteAdapter = new SQLiteAdapter(this);
mySQLiteAdapter.openToWrite();



cursor = mySQLiteAdapter.queueAll();
String[] from = new String[]{ SQLiteAdapter.COLUMN_NAME, SQLiteAdapter.COLUMN_EMAIL,SQLiteAdapter.COLUMN_PHONE, SQLiteAdapter.COLUMN_ADDRESS};

int[] to = new int[]{R.id.text1, R.id.text2,R.id.text3, R.id.text4};

cursorAdapter = new SimpleCursorAdapter(this, R.layout.row, cursor, from, to);
listContent.setAdapter(cursorAdapter);



listContent.setOnItemClickListener(new OnItemClickListener() {

    public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3) {

        String str = ((TextView)arg1).getText().toString();
        Toast.makeText(Activity2.this, str, Toast.LENGTH_SHORT).show();
    }
});



}


   Button.OnClickListener buttonDeleteRowOnClickListener = new Button.OnClickListener(){

       public void onClick(View arg0) {

     //    String n = inputContent1.getText().toString();
     //    mySQLiteAdapter.deleteRow(n);
           updateList();
           Toast.makeText(Activity2.this, "Entry Deleted", Toast.LENGTH_SHORT).show();      


       }
        };

        Button.OnClickListener buttonDeleteAllOnClickListener
        = new Button.OnClickListener(){
       public void onClick(View arg0) {

        mySQLiteAdapter.deleteAll();
        updateList();
        Toast.makeText(Activity2.this, "All Entries Deleted", Toast.LENGTH_SHORT).show();      

       }
        };

        private void updateList(){
              cursor.requery();
               }
}

Po użyciu swojej drogi dostałem błędy:

07-27 07:52:15.726: E/AndroidRuntime(856): FATAL EXCEPTION: main
07-27 07:52:15.726: E/AndroidRuntime(856): java.lang.ClassCastException:              android.widget.LinearLayout
07-27 07:52:15.726: E/AndroidRuntime(856):  at  com.example.deneme.Activity2$3.onItemClick(Activity2.java:58)
07-27 07:52:15.726: E/AndroidRuntime(856):  at android.widget.AdapterView.performItemClick(AdapterView.java:284)
07-27 07:52:15.726: E/AndroidRuntime(856):  at android.widget.ListView.performItemClick(ListView.java:3513)
07-27 07:52:15.726: E/AndroidRuntime(856):  at android.widget.AbsListView$PerformClick.run(AbsListView.java:1812)

questionAnswers(3)

yourAnswerToTheQuestion