0

In the following code, on click of list item I want to fetch variable present inside the object, How I can achive this

Below is code snippet

 private void onListViewItemClick() {
    // TODO Auto-generated method stub
    // item click switch to next activity
    listCustomListViewId.setOnItemClickListener(new OnItemClickListener() {
        /* on click gets list view item id */
        public void onItemClick(AdapterView<?> myAdapter, View myView,
                int myItemInt, long mylng) {
            // fetching clicked item id
            Object o = listCustomListViewId.getItemAtPosition(myItemInt);
            Log.i("Victory Item Id:.....", String.valueOf(o);
            long strid = (long) (listCustomListViewId
                    .getItemIdAtPosition((int) mylng));
            Log.i("Item Id...#######", String.valueOf(strid));

            /* switch on next 'ListItemDeleteUpdateActivity' activity */
            Intent intent = new Intent(FeedsActivity.this,
                    VictoryDetailActivity.class);

            intent.putExtra("customElements", o.toString());
            startActivity(intent);
        }
    });

}

I have tried to get data into Object but unable to fetch.

4 Answers 4

0
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {   
super.onListItemClick(l, v, position, id);

// Get the data associated with selected item
Object item = l.getItemAtPosition(position);
String myitem = item.toString();
edittxt.setText("Selected item is :"+ myitem); // You can Set EditText from Here.

 /* switch on next 'VictoryDetailActivity' activity */
        Intent intent = new Intent(FeedsActivity.this,VictoryDetailActivity.class);
        intent.putExtra("customElements",myitem);
        startActivity(intent);
}

Hope this helps you.

0

On DataSource you have probably an collection of something. myItemInt represent the corresponding item in your collection to the item clicked. Use that.

If you have some views inside the clicked view you need to get, use findViewbyId on myView, like this:

myView.findViewbyId(R.id.myEditTextControl)  //demo, use yours

If this answer is not enough for you, post some code from your adapter and tell us more details about what you need to do.

0

To handle events when the items of ListView is selected. You must override onListItemClick() method. The medthod have 4 parameters:

 @Override
 protected void onListItemClickonListItemClick(ListView l, View v, int position, long id)

To get information about ItemSelected, you just call getItemAtPosition(position) method to return a object which contains data.

0

It should be onListItemClick()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.