Partage
  • Partager sur Facebook
  • Partager sur Twitter

Get the TextView value of the gridview while click

Sujet résolu
    10 décembre 2018 à 19:43:06

    I am trying to get the value of TextView from gridView, when I click on an element of 
    the list. The adapter consists of 2 textViews. This is the ListAdapter class. 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; } } When I click on an element of my list (for example at the third position), I would like
    to get the TextViewName (Customer.getName()) which corresponds to that id. I have tryed 
    to explain it at gridViewCustomer.setOnItemClickListener in 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 gridViewPflanzen = (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(); } }); }

    -
    Edité par K070913S080913 10 décembre 2018 à 19:44:53

    • Partager sur Facebook
    • Partager sur Twitter

    Get the TextView value of the gridview while click

    × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
    × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
    • Editeur
    • Markdown