In the application I am building I have 2 listviews with, among other elements, 2 buttons on every row, one for eliminating that row and the other to pass to another activity using an Intent. I am detecting clicks on both buttons by setting click listeners on both buttons on the getView method of the Adapter class. The first button was something I couldn't figure out, because I needed to identify in which listview the button was clicked and the position of the clicked row which I couldn't realize how to do. The second one I thought would be easier since all I needed to do was Intents. However I needed to call a method from the activity class (had to instance it) since I couldn't make Intents in a non-activity class. This last one threw a NullPointerException. Will post all code & logcat in a while, be right back, any possible help will be appreciated.
私はあなたのコードを見る必要がありますが、基本的にアダプターのコード内でインテントを呼び出すことができるようにするために私のために働いたのは、ホストアクティビティを使用することでした。
このようなもの:
item_new = (TextView) convertView.findViewById(R.id.my_view);
Activity host = (Activity) item_new.getContext();
Intent intent = new Intent(host, MyActivity.class);
host.startActivity(intent);
あなたがコードを投稿するなら、多分私はより多くの詳細を与えることができます
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加