views:

40

answers:

2

What I'm trying to do is set the text of the item I click on into the myEditText. Not sure how to access the specific item in ListView though...

    ListView myListView = (ListView)findViewById(R.id.myListView);
    final EditText myEditText = (EditText)findViewById(R.id.myEditText);
    ...
    myListView.setAdapter(aa);

    myListView.setOnClickListener(new OnClickListener(){
        public void onClick(View v){
            myEditText.setText("You clicked something!");
        }
    });
+1  A: 

I'm a newbie but recently did this, so if you can understand my code snippet, something like this:

setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, array_of_something));       

ListView lv = getListView();
lv.setTextFilterEnabled(true);

lv.setOnItemClickListener(new OnItemClickListener() {     

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int arg2, long arg3) {

        String item_clicked_on = (String)((TextView) view).getText();                                            

        }
      });

Maybe this helps?

ShadowGod
yeah thats pretty awesome actually. Have you devd anything cool yet?
codeninja
not yet:) Just learning/working on some things.
ShadowGod
+1  A: 

Don't do any of those. When using a listview, set on onItemClickListener and it will give you the position of the listitem that was clicked.

lv.setOnItemClickListener(new OnItemClickListener() {
    public void onItemClick(AdapterView<?> parent, View view,
        int position, long id) {

now position is the position of the listitem that was clicked.

Falmarri