Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8413503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:55:58+00:00 2026-06-10T00:55:58+00:00

I am trying to show a list that when I pressed it in that

  • 0

I am trying to show a list that when I pressed it in that position I would like to show an image that is gone and to change the typeface of that row. So first I have a xml file with a simple list and then another xml for each row, this one:

<ImageView
    android:id="@+id/icono"
    android:layout_gravity="center"
    android:layout_marginRight="5dip"/>

<RelativeLayout
    android:id="@+id/RelativeLayout1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_centerVertical="true"
        android:text="TextView" />

    <ImageView
        android:id="@+id/image_tick_ingred"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="false"
        android:layout_alignParentLeft="false"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="false"
        android:layout_alignRight="@id/textView1"
        android:layout_centerVertical="true"
        android:src="@android:drawable/presence_online" />
</RelativeLayout>

So that is the code to each row, contains an image on the left then a text and finally another image on the right of the row. And the java code:

public class TabIngred extends ListActivity {

    ImageView img;

public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.rellenas_ingr); //the list xml layout

        Bundle extras = getIntent().getExtras(); //get data
        if (extras != null) {
            String ingredientesLista[] = extras.getStringArray("ingredientesLista");
            int[] ingredientesImagen=extras.getIntArray("ingredientesImagen");

            setListAdapter (new IngredienteAdapter(this, R.layout.rellenas_ingr_fila, ingredientesLista, ingredientesImagen));
            getListView().setChoiceMode(2);
        }

}

private class IngredienteAdapter extends ArrayAdapter<String>{

    private String listaIngred[];
    private int[] listaImagenes;

    public IngredienteAdapter(Context context, int textViewResourceId, String ingredientesLista[], int[] ingredientesImagen) {
        super(context, textViewResourceId, ingredientesLista);
        this.listaIngred = ingredientesLista;
        this.listaImagenes=ingredientesImagen;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        View v = convertView;
        if (v == null) {
            LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            // XML de la vista de la fila
            v = vi.inflate(R.layout.rellenas_ingr_fila, null); //the row for the listview
        }
        String ingred = listaIngred[position];
        int imagen=listaImagenes[position];
        int tickImagen = R.drawable.tick_ingred;//set the image to a tick 


        if (ingred != null) {
            TextView ttitulo = (TextView) v.findViewById(R.id.textView1);
            if (ttitulo != null) {
                ttitulo.setText(ingred);
            }
            ImageView timagen = (ImageView) v.findViewById(R.id.icono);
            if (timagen != null) {
                timagen.setImageResource(imagen);
            }
            ImageView ttick = (ImageView) v.findViewById(R.id.image_tick_ingred);
            if (ttick != null) {
                ttick.setImageResource(tickImagen);
                ttick.setVisibility(View.GONE);
            }
        }   
        return v;
    }
}

 @Override
 public void onListItemClick(ListView l, View v, int position, long id) {

     img=(ImageView)v.findViewById(R.id.image_tick_ingred);
     TextView t= (TextView)v.findViewById(R.id.textView1);

     if(img.getVisibility()==View.GONE){

         t.setTypeface(null, Typeface.BOLD);
         img.setVisibility(View.VISIBLE);

     }else {
         t.setTypeface(null, Typeface.NORMAL);
         img.setVisibility(View.GONE);

     }
 }
}

So, I define the getview(), I put the image on gone (thats works), but then the OnlistItemClick() doesn´t work. First when I selected an Item the image isn´t visible and apart for that indefferently the position I pressed the first row is which change the typeface, not the item what I pressed.

Thanks 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T00:55:59+00:00Added an answer on June 10, 2026 at 12:55 am

    The problem was that I define getListView().setChoiceMode(2); and that was because it doesn´t work, I delete the line and works perfect!!

    Thanks after all!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to display a list that I build using PySide. It
I have an ajax list that updates (as notifications). However, what I'm trying to
I'm trying to show a list of messages to the user where the first
I'm trying to show a list with shopping cart items in a row with
I'm trying to make something like a spellchecker, that will list possible words under
I'm trying to create an image button that, when pressed, presents the users a
I'm trying to show a list of games by date organized so that I
I'm trying to create a dynamic list that will show item of my city
n00b problem- I am trying to have a list show the most recent entry
Im trying to retrieve the position of the pressed button, in a list of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.