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 9211097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:13:08+00:00 2026-06-18T01:13:08+00:00

I couldn’t select an item on ListView. I use Custom Adapter to set content

  • 0

I couldn’t select an item on ListView. I use Custom Adapter to set content of ListView. I have set OnItemClickListener of ListView. However, it didn’t respond. I appriciate your help. Here is my code:

List Item (connections.xml):

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:padding="6dip" >


    <LinearLayout
        android:layout_width="0dip"
        android:layout_height="wrap_content"
        android:layout_weight="0.90"
        android:orientation="vertical" >
        <TextView
        android:id="@+id/connname"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"        
        android:text="@string/acc1" />
    <TextView
        android:id="@+id/conntype"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"    
        android:textSize="9sp"    
        android:text="@string/acctype1" />
    </LinearLayout>

    <CheckBox
        android:id="@+id/checkBox1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</LinearLayout>

The screen which containt ListView (groupconnections.xml):

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <LinearLayout android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dip"  
        android:layout_marginBottom="5dip"
        android:orientation="vertical"
        android:id="@+id/textOperLayout">
        <TextView
            android:id="@+id/connectionsLabel"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/connections"
            android:textColor="@color/conn_text"
            android:textSize="25sp"
            android:paddingTop="5dp"
            android:paddingBottom="5dp"
            android:paddingLeft="15dp" 
            android:background="@color/conn_back"/>


        <EditText
            android:id="@+id/searchEditText"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:hint="@string/searchhint"
            android:layout_marginTop="10dp"
            android:inputType="textPersonName" />
    </LinearLayout>

    <LinearLayout android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="100dip"  
        android:layout_marginBottom="50dip"
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_above="@+id/textOperLayout"
        android:id="@+id/listviewlayout">
        <ListView
            android:id="@+id/connectionlist"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:choiceMode="singleChoice"  />
    </LinearLayout>

    <Button
        android:id="@+id/addConnCommitButton"
        android:layout_width="fill_parent"
        android:layout_height="50dp"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginLeft="15dp"
        android:text="@string/commitToAdd" />

</RelativeLayout>

The related activity (AddMoreConnections.xml):

public class AddMoreConnections extends Activity implements OnItemClickListener{

    private ListView mainListView ;  
    private ArrayAdapter<AbstractHolder> listAdapter ; 
    private TextView searchConnTextView;
    private Button commitButton;
    private ArrayList<AbstractHolder> connlist;
    private ArrayList<AbstractHolder> listNotOnView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //Generate list View from ArrayLis 

        setContentView(R.layout.groupconnections);  

        addListenerOnSearchConnTextView();
        //Initialize properties   
        mainListView = (ListView) findViewById( R.id.connectionlist );  
        mainListView.setOnItemClickListener(this);

        // Create and populate a List of planet names.
        listNotOnView = new ArrayList<AbstractHolder>();
        connlist = new ArrayList<AbstractHolder>(5);
        Iterator<AbstractHolder> iter = SocialRssModel.holders.values().iterator();
        while(iter.hasNext())
            connlist.add(iter.next());

        // Create ArrayAdapter using the planet list.  
        listAdapter = new CustomAdapter(this,
                R.layout.connlist, connlist);
        mainListView.setAdapter( listAdapter );

    }
    public void addListenerToFinishButton(){
        commitButton = (Button) findViewById(R.id.addConnCommitButton);
        commitButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {


            }
        });
    }
    public void addListenerOnSearchConnTextView(){
        searchConnTextView = (TextView) findViewById(R.id.searchEditText);
        searchConnTextView.addTextChangedListener(new TextWatcher() {

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                int listNotOnViewsize = listNotOnView.size();
                int connlistsize = connlist.size();

                for(int i= 0; i < connlistsize; i++){
                    if(!connlist.get(i).connNameContains(s.toString())){
                        listNotOnView.add(connlist.remove(i));
                        i--;
                        connlistsize--;
                    }
                }
                for(int i=0; i < listNotOnViewsize; i++){
                    if(listNotOnView.get(i).connNameContains(s.toString())){
                        connlist.add(listNotOnView.remove(i));
                        i--;
                        listNotOnViewsize--;
                    }
                }
                ((CustomAdapter) listAdapter).updateList(connlist);
                listAdapter.notifyDataSetChanged();

            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {                
            }

            @Override
            public void afterTextChanged(Editable s) {              
            }
        });
    }
    @Override
    public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
        AbstractHolder temp = (AbstractHolder)mainListView.getItemAtPosition(arg2);
        Intent i = new Intent(this, CategoryContentViewerController.class);
        Bundle b = new Bundle();
        b.putInt("AbstractHolderKey", temp.getId());
        i.putExtras(b);
        startActivity(i);
        finish();
    }
    private class CustomAdapter extends ArrayAdapter<AbstractHolder> {

          private ArrayList<AbstractHolder> connectionList;

          public CustomAdapter(Context context, int textViewResourceId, ArrayList<AbstractHolder> connList) {
              super(context, textViewResourceId, connList);
              this.connectionList = new ArrayList<AbstractHolder>();
              this.connectionList.addAll(connList);
          }
          public void updateList(ArrayList<AbstractHolder> connList){
              connectionList.clear();
              connectionList.addAll(connList);
          }
          private class ViewHolder {
              TextView name;
              TextView acctype;
              CheckBox sel;
          }



          @Override
          public View getView(int position, View convertView, ViewGroup parent) {

              ViewHolder holder = null;
              Log.v("ConvertView", String.valueOf(position));

              if (convertView == null) {
                  LayoutInflater vi = (LayoutInflater)(((Activity)this.getContext()).getSystemService(Context.LAYOUT_INFLATER_SERVICE));
                  convertView = vi.inflate(R.layout.connlist, null);

                  holder = new ViewHolder();
                  holder.name = (TextView) convertView.findViewById(R.id.connname);
                  holder.acctype = (TextView) convertView.findViewById(R.id.conntype);
                  holder.sel = (CheckBox) convertView.findViewById(R.id.checkBox1);
                  convertView.setTag(holder);


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

              AbstractHolder conn = connectionList.get(position);
              holder.name.setText(conn.getName());
              holder.acctype.setText(conn.getConntype());
              holder.sel.setChecked(conn.isSelected());
              holder.sel.setTag(conn);

              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-18T01:13:09+00:00Added an answer on June 18, 2026 at 1:13 am

    It is related to checkbox item in connections.xml which is the list row item. If I remove checkbox, related listeners responses. I think, it may be thought there is no need a setItemOnClickListener(..) method since each row has a checkbox. Or it is a bug.

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

Sidebar

Related Questions

Couldn't find an answer to this one. I have a WPF ListView control that
I couldn't find anything similar to this anywhere. I have an array of pointers
I couldn't find this in the documentation. If I have a complex object in
(I couldn't make up a good title, sorry) So I use this pagination: $page
Couldn't find a function for this. I'm assuming I need to use regex? I'm
Couldn't find a better way to phrase this question. Here's the deal: I have
Couldn't find this on stackoverflow and I did have an example of it which
couldn't find my solution. hope you can help. I want to have a url
Couldn't find anything about this topic. I have a Windows TCP C++ server application
Couldn't solve it by myself so I've decided to use the help of the

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.