Click a TextView in a ListView to open another layout page

I am trying to enable a textview on my listview clickable and then open another layout:

  private class IndexListAdapter extends ArrayAdapter<Index>{
        public IndexListAdapter(){
            super(MainActivity.this, R.layout.listview_item, index);
        }


        @Override
        public View getView(int position, View view, ViewGroup parent){
            if (view == null)
                view = getLayoutInflater().inflate(R.layout.listview_item, parent, false);

            Index currentIndex = index.get(position);

            TextView name = (TextView) view.findViewById(R.id.pName);
            name.setText(currentIndex.getName());

            name.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    items.add(new Item(patientTxt.getText().toString(), operatorTxt.getText().toString(),
                            serialTxt.getText().toString(), deviceTxt.getText().toString(), dateTxt.getText().toString(),
                            assetTxt.getText().toString(), locationTxt.getText().toString(), qcTxt.getText().toString()));
                    populateList();
                    Intent intent = new Intent(MainActivity.this, Item.class);
                    startActivity(intent);
                    finish();
                }
            });

            return view;
        }
    }

what i am trying to do is that I will have one item which is a name to show on a listview_item or a list tab and when I click on the name it will open up another layout or page to display another list of items.

Answers


You cannot call like this in your custom adapter so you will try like this it will work

 Intent intent = new Intent(MainActivity.this, Item.class);
                startActivity(intent);
                finish();

You will change into this. You just send the context and using that one call the intent

 Intent i = new Intent(mContext, TabActivityPacs.class);
            i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            i.putExtra("STUDY", study);
            mContext.startActivity(i);

If you not able to get click event of TextView

add this attribute for your TextView

android:focusableInTouchMode="false"

also add

android:descendantFocusability="blocksDescendants" 

for your ListView


Need Your Help

Symfony2 Accessing route variables

php symfony routing

I know I can access current route name by $request-&gt;get('_route');.

C++ repeated indirect vs direct access

c++ performance game-engine

This is a rather pedantic question, but I want to get the most performance out of my game. This game includes accessing an array of a data structure, but I dont know the size of this array (e.g. pl...