簡體   English   中英

新列表視圖項目不可單擊

[英]The New List View Items not Clickable

我在android中是一個非常新的人。我正在創建一個列表視圖,每當我單擊列表的項目時,它都會顯示第二個列表視圖,但是第二個列表視圖上的所有項目都是不可點擊的。 我已經嘗試了所有解決方案以使第二個列表中的項目可單擊,但是沒有一個對我有用。 到目前為止,這是我的代碼:

主要活動 :

public class MainActivity extends AppCompatActivity {
    String[] boundryitems = {"Boundry Wall","Front Elevation","Corridor","Kitchen","Bedroom1"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        //Boundry List Adapter

        final ArrayAdapter boundry_Item1 = new ArrayAdapter<String>(this,
                R.layout.activity_main,R.id.texti, boundryitems);
        ListView listView11 = (ListView) findViewById(R.id.listvi);
        listView11.setAdapter(boundry_Item1);


        listView11.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view,
                                    int position, long id) {
                if (position == 0) {

                    Intent myIntent = new Intent(view.getContext(), item1.class);

                    startActivityForResult(myIntent, 0);

                }
                if (position == 1) {
                    Intent myIntent = new Intent(view.getContext(), item1.class);
                    startActivityForResult(myIntent, 0);

                }

                if (position == 2) {
                    Intent myIntent = new Intent(view.getContext(), item1.class);
                    startActivityForResult(myIntent, 0);
                }

                if (position == 3) {
                    Intent myIntent = new Intent(view.getContext(), item1.class);
                    startActivityForResult(myIntent, 0);
                }

                if (position == 4) {
                    Intent myIntent = new Intent(view.getContext(), item1.class);
                    startActivityForResult(myIntent, 0);
                }

                if (position == 5) {
                    Intent myIntent = new Intent(view.getContext(), item1.class);
                    startActivityForResult(myIntent, 0);
                }

                if (position == 6) {
                    Intent myIntent = new Intent(view.getContext(), item1.class);
                    startActivityForResult(myIntent, 0);
                }

                if (position == 7) {
                    Intent myIntent = new Intent(view.getContext(), item1.class);
                        startActivityForResult(myIntent, 0);
                    }
                }
            });
        }
    }

項目1(包含第二個Listview):

 public class item1 extends Activity {

        String[] snaglistciv = {"Paint","Garbage Room","Pump Room","Lights","Joint"};
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.snag_item);

    //Snag List Adapter

            final ArrayAdapter adapterSnag_Item = new ArrayAdapter<String>(this,
                    R.layout.snag_item,R.id.textsnag, snaglistciv);

            final ListView listView = (ListView) findViewById(R.id.listsnag);
            listView.setAdapter(adapterSnag_Item);



            listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                public void onItemClick(AdapterView<?> parent, View view,
                                        int position, long id) {
                    if (position == 0) {


                        Intent myIntent = new Intent(view.getContext(), camerapic.class);

                        startActivityForResult(myIntent, 0);

                    }
                    if (position == 1) {
                        Intent myIntent = new Intent(view.getContext(), camerapic.class);
                        startActivityForResult(myIntent, 0);

                    }

                    if (position == 2) {
                        Intent myIntent = new Intent(view.getContext(), camerapic.class);
                        startActivityForResult(myIntent, 0);
                    }

                    if (position == 3) {
                        Intent myIntent = new Intent(view.getContext(), camerapic.class);
                        startActivityForResult(myIntent, 0);
                    }

                    if (position == 4) {
                        Intent myIntent = new Intent(view.getContext(), camerapic.class);
                        startActivityForResult(myIntent, 0);
                    }

                    if (position == 5) {
                        Intent myIntent = new Intent(view.getContext(), item1.class);
                        startActivityForResult(myIntent, 0);
                    }

                    if (position == 6) {
                        Intent myIntent = new Intent(view.getContext(), item1.class);
                        startActivityForResult(myIntent, 0);
                    }

                    if (position == 7) {
                        Intent myIntent = new Intent(view.getContext(), item1.class);
                        startActivityForResult(myIntent, 0);
                    }
                }
            });
        }
    }

您的活動的contentView和listview的項目視圖相同??? R.layout.snag_item

        setContentView(R.layout.snag_item);

        final ArrayAdapter adapterSnag_Item = new ArrayAdapter<String>(this,
                R.layout.snag_item,R.id.textsnag, snaglistciv);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM