I tried to get answer from different similar questions here but didn't get any answer.
Actually I am trying to get values from multiple textViews of any listview item(s).
Here is the code
ListView listView = getListView();
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int postion, long id) {
String contactId = ((TextView) findViewById(R.id.cid)).getText().toString();
String contactName= ((TextView) findViewById(R.id.contactName)).getText().toString();
String contactNo= ((TextView) findViewById(R.id.contactNo)).getText().toString();
Intent i = new Intent(getApplicationContext(), editContactActivity.class);
i.putExtra(TAG_ID, contactId );
i.putExtra(TAG_NAME, contactName);
i.putExtra(TAG_CONTACT_NO, contactNo);
startActivityForResult(i, 100);
}
});
What result i am getting, I am getting textviews value of first item(Position) in listview, either i am clicking any item but i am getting textviews value of first item(Position) in listview, Here is the code how i am getting values on other activity
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.edit_contact);
btnSave = (Button) findViewById(R.id.btnSaveContact);
btnDelete = (Button) findViewById(R.id.btnDeleteContact);
Intent i = getIntent();
cId = i.getStringExtra(TAG_CONTACT_ID);
cNameTxt = i.getStringExtra(TAG_CONTACT_NAME);
cNumberTxt = i.getStringExtra(TAG_CONTACT_NUMBER);
//Log.d("Value of contact name", cNameTxt);
//Log.d("Value of contact name", cNumberTxt);
TextView contactIdTxtView = (TextView) findViewById(R.id.cid);
cName = (EditText) findViewById(R.id.editCName);
cNumber = (EditText) findViewById(R.id.editCNumber);
cName.setText(cId);
cNumber.setText(cNumberTxt);
}
I will be very thankful if anyone will help in detail Thanks Regard Akmal Rasool
I am getting textviews value of first item(Position) in listview
Every time you use findViewById()
tell it to look in this row only:
(TextView) view.findViewById(R.id.cid)
//Add this ^^^^^
All together:
@Override
public void onItemClick(AdapterView<?> parent, View view, int postion, long id) {
String contactId = ((TextView) view.findViewById(R.id.cid)).getText().toString();
// Again use view ^^^^^
// Repeat this for contactName and contactNo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With