2

ボタンをクリックするとedit_remainder、アクティビティを別のアクティビティに移動したいと思います。

しかし、クラスが ArrayAdapter を拡張する場所で、別のアクティビティに移動する方法がわかりません。

Intent クラスの例を教えてください。

public class mylist extends ArrayAdapter<String> implements OnClickListener 
{

  private final Context context;
  private final String[] values;
  Button edit_remainder;

  public mylist(Context context, String[] values) {
    super(context, R.layout.some, values);
    this.context = context;
    this.values = values;
  }

  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View rowView = inflater.inflate(R.layout.buttonadd, parent, false);
    edit_remeinder=(Button) rowView.findViewById(R.id.btnEdit);
    edit_remeinder.setOnClickListener(this);
    return rowView;
  }

  public void onClick(View v) {
    Toast.makeText(getContext(), "hi", 1000).show();
    // please enter moving code here
  }
}
4

4 に答える 4

0

ここで明示的なインテントを次のように起動します。

Intent i=new Intent(context,anotheractivity.class);
startActivity(i);

ここで、コンテキストはアプリケーション コンテキストである可能性があります。

于 2012-05-03T04:30:22.860 に答える
0

ここでは listview 用に作成しましたが、独自のアプリケーションで試すことができます。独自のアダプターではなく、メイン アクティビティでインテントを渡します。

mainActivity.java

public void onCreate(Bundle savedInstanceState) {  
    super.onCreate(savedInstanceState);  
    setContentView(R.layout.main);  

    lview = (ListView) findViewById(R.id.listView2);  
    lviewAdapter = new ListViewAdapter(this, month, number);  //here ListViewAdapter is my own adapter

    System.out.println("adapter => "+lviewAdapter.getCount());  

    lview.setAdapter(lviewAdapter);  

    lview.setOnItemClickListener(this);  
}  

public void onItemClick(AdapterView<?> arg0, View arg1, int position, long id) {  
    // TODO Auto-generated method stub  
    Toast.makeText(this,"Title => "+month[position]+"=> n Description"+number[position], Toast.LENGTH_SHORT).show();  

     // here your intent code

}  
}  

この onclick メソッドをメイン アクティビティに配置して、もう一度お試しください。

public void onClick(View v) {
Toast.makeText(getContext(), "hi", 1000).show();
// please enter moving code here

}
于 2012-05-04T04:11:03.937 に答える
0

If I understand correctly, you wish to transfer control to another activity when the user taps on a list item. You will need to issue an intent.

Here's a tutorial: http://www.vogella.com/articles/AndroidIntent/article.html

于 2012-05-02T19:45:45.167 に答える
0

独自のアダプター (mylist) を作成していますか? はいの場合は、mylist アダプターを呼び出してメイン クラスにインテントを渡します。

于 2012-05-03T05:02:07.277 に答える