Я пытаюсь получить значение TextView из gridView, когда я нажимаю на элемент списка.Адаптер состоит из 2 текстовых представлений.Это класс ListAdapter.
public class ListAdapter extends BaseAdapter {
private Context context;
private int layout;
private ArrayList<Customer> CustomerList;
public ListAdapter(Context CustomerList, int customer_activity, ArrayList<Customer> Customer) {
this.context = CustomerList;
this.layout = customer_activity;
this.CustomerList = Customer;
}
@Override
public int getCount() {
return CustomerList.size();
}
@Override
public Object getItem(int position) {
return CustomerList.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
private class ViewHolder{
TextView textViewJob, textViewName;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
ViewHolder holder = new ViewHolder();
if(row == null)
{
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = inflater.inflate(layout,null);
holder.textViewJob = (TextView)row.findViewById(R.id.tvJobAdap);
holder.textViewName = (TextView)row.findViewById(R.id.tvNameAdap);
row.setTag(holder);
}
else {
holder = (ViewHolder)row.getTag();
}
Customer Customer = CustomerList.get(position);
holder.textViewJob.setText(Customer.getJob());
holder.textViewName.setText(Customer.getName());
return row;
}
}
Когда я нажимаю на элемент моего списка (например, на третьей позиции), я хотел бы получить TextViewName (Customer.getName ()), который соответствует этому идентификатору.Я попытался объяснить это в gridViewCustomer.setOnItemClickListener в Toast.makeText
GridView gridViewCustomer;
ArrayList<Customer> customer;
ListeAdapter adapter = null;
public String selectedItemText;
//Referenz of the SQLiteHelper class
public static SQLiteHelper sqLiteHelper;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.Customer_activity);
sqLiteHelper = new SQLiteHelper(CustomerListe.this, "Customer.sqlite", null, 3);
//Customer List
gridViewCustomer = (GridView) findViewById(R.id.gvCustomerList);
customer = new ArrayList<>();
adapter = new ListeAdapter(this, R.layout.customer_activity, customer);
gridViewCustomer.setAdapter(adapter);
gridViewCustomer.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,final int position, long id) {
Toast.makeText(ListActivity.this, "You have clicked on the element with id =" + id, Toast.LENGTH_SHORT).show();
Toast.makeText(ListActivity.this, "Please how could I get the TextView (TextViewName) corresponding to that id ?", Toast.LENGTH_SHORT).show();
}
});
}