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

  • Home
  • SEARCH
  • 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 8508559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:11:39+00:00 2026-06-11T03:11:39+00:00

I have problem with the get the listview item when click listitem. I Got

  • 0

I have problem with the get the listview item when click listitem.
I Got listview item for the simple listview(Arrayadapter), but I have face problem for the custom listview.

I am using

listview.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> myAdapter, View myView, int pos, long mylng) {

  //String  selectedFromList = (String) listview.getItemAtPosition(pos);
   String  selectedFromList = (String) adapter.getItem(pos);

    System.out.println("selected value >> >> >> >> >> >>"+selectedFromList);

    SelectedAnswer.setAnswer(selectedFromList);

              }

          });

Into Logcat give me the null value :

I/System.out( 1238): selected value >> >> >> >> >> >>null

main.class

 protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.quiz_questions);

        listview = (ListView) findViewById(R.id.questions_list);

        GoToNextQuestion();
  }

private void GoToNextQuestion() {
    // TODO Auto-generated method stub

     currentGame = ((Quizapplication)getApplication()).getCurrentGame();
    currentQ = currentGame.getNextQuestion();

       setQuestions();

    listview.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> myAdapter, View myView, int pos, long mylng) {

  //String  selectedFromList = (String) listview.getItemAtPosition(pos);
   String  selectedFromList = (String) adapter.getItem(pos);

    System.out.println("selected value >> >> >> >> >> >>"+selectedFromList);

    SelectedAnswer.setAnswer(selectedFromList);

              }

          });


}

 private void setQuestions() {


    // set the available options
    List<String> answers = currentQ.getQuestionOptions();
    System.out.println("value of the options >>>>>>>>>>>>>:"+answers); 


     //ArrayAdapter< String> myadapter = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_list_item_single_choice ,answers);

    //ArrayAdapter< String> adapter = new ArrayAdapter<String>(this, R.layout.quiz_questions_listitem, answers);        

             // working for the simple adapter

      adapter = new ListviewAdapter(this,answers);

     listview.setAdapter(adapter);
     //listview.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
}


 }

EDIT:

 public class ListviewAdapter extends BaseAdapter{

public List<String> Questions;  

public Activity context;  
public LayoutInflater inflater;


public ListviewAdapter(Activity context,List<String> answers) {  
    super();  

    this.context = context;  
    this.Questions = answers;  

    this.inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);  
}  

@Override  
public int getCount() {  
    // TODO Auto-generated method stub  
    return Questions.size();  
}  

@Override  
public Object getItem(int position) {  
    // TODO Auto-generated method stub  
    return null;  
}  

@Override  
public long getItemId(int position) {  
    // TODO Auto-generated method stub  
    return 0;  
}  

public static class ViewHolder  
{  

    TextView txtquestion;  
}  

@Override  
public View getView(int position, View convertView, ViewGroup parent) {  
    // TODO Auto-generated method stub  

    ViewHolder holder;  
    if(convertView==null)  
    {  
        holder = new ViewHolder();  
        convertView = inflater.inflate(R.layout.quiz_questions_listitem, null);  


        holder.txtquestion = (TextView) convertView.findViewById(R.id.textView_option);  

        convertView.setTag(holder);  

      /*  convertView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                 System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>"+v.toString());
                notifyDataSetChanged();

                 SelectedAnswer.setAnswer(v.toString());
            }
        });*/
    }  
    else  
        holder=(ViewHolder)convertView.getTag();  

    holder.txtquestion.setText(Questions.get(position));  

    return convertView;  
}   

}
  • 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-11T03:11:41+00:00Added an answer on June 11, 2026 at 3:11 am

    You probably return null from the getItem() method of your custom adapter, ListviewAdapter(you should add the code for the adapter). Also, there is no need to set the listener on the ListView again.

    Modify your getItem() method like this:

    @Override  
    public Object getItem(int position) {     
        return Questions.get(position);  
    }  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some problem to get the utf-8 string from PHP using jQuery $.load()
I am working with MyFaces/Primefaces and I have a problem to get information using
I have got a problem to get back a parameter from my view to
I have problem with android 4.0.3. I'm using the method below to get local
I have a problem with ListView. the thing is that when I click on
I have this strange problem about loading images using AsyncTask in ListView.In my ListView,
i have problem with listview... i'm trying to add OnClickListener but in still doesn't
I have a listview and when you click an item in the list I
I have a ListView in AcitivityA that is populated using a custom SimpleCursorAdapter called
I have a big problem: I have a listview and each item links to

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.