0

Is it possible to retrieve text from a specific TextView element in a row inside a ListView where every row contains its own Layout.xml with 4 different TextViews? A row looks like --> | TextView1 TextView2 TextView3 TextView4 |. The rowcount of my ListView is depending on the row count of my SQLite database which the ListView is populated from. For example: if I click row #1 i want TextView1 for this row and if I click row #2 i want TextView1 for this particular row.

I Hope you understand, english ain't my native language.

1
  • So when you click on a specific element of the TextView, you need a 'Select the row text' action to be performed if that what you mean then i can the provide you some code. Commented Jul 30, 2013 at 23:30

2 Answers 2

1

I'm not really sure if I understood you, but I think you want to add a AdapterView.OnItemClickListener to your ListView. Implement this listener which only has one method:

onItemClick(AdapterView<?> parent, View view, int position, long id)

In your case view will be the row the user clicked and item is the position of the row in your adapter.

To retrieve the text of the row, first you should get the TextView (if your view is a container) with something like

 TextView textView = (TextView) view.findViewById(R.id.your_textview_id);

and then retrieve the text with a call to textView.getText()

Hope it helps

Sign up to request clarification or add additional context in comments.

1 Comment

Javier, thank you very much! I followed your advice and now it works like a charm!
0

If you're using an adapter based on the 'BaseAdapter' then You need to add an onClickListener for each TextView you want to retrieve its content inside your getView() method :

private class ViewHolder 
{
    TextView Tv1;
    TextView Tv2;
}
public View getView(final int position, View convertView, ViewGroup parent) {

    ViewHolder holder;
    if (convertView==null)
    {
        holder=new ViewHolder();
        convertView = inflater.inflate(R.layout.yourXmlSource, null);
        holder.tv1 = (TextView)convertView.findViewById(R.id.tv1);
        holder.tv2 = (TextView)convertView.findViewById(R.id.tv2);
    }

    else
    {
        holder = (ViewHolder) convertView.getTag();
    }

//Code to fill your Rows from the database here


    holder.tv1.setOnClickListener(new OnClickListener() 
    {

        @Override
        public void onClick(View v) 
        {

        Toast toast = Toast.makeText(v.getConext(), (TextView)v, Toast.LENGTH_LONG);
toast.show();

        }
    });
}

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.