如何从OnItemClick()调用java类?

时间:2011-08-12 09:31:25

标签: android android-widget android-intent

从OnItemClickListener小部件调用java类时遇到问题..

  private OnItemClickListener detailClickListener = new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
                Intent productDetailsIntent = new Intent(getBaseContext(),MenuRestaurantActivity.class);
                startActivity(productDetailsIntent);
    }
        };

currentActivity中的参数不会发送到anotherActivity类..

如何解决?

感谢您的关注..

3 个答案:

答案 0 :(得分:1)

您必须在AndroidManifest.xml文件中声明以下行,否则会产生错误。

<activity android:name=".MenuRestaurantActivity"  android:label="@string/app_name">
</activity>

答案 1 :(得分:0)

 private OnItemClickListener detailClickListener = new OnItemClickListener() {
     public void onItemClick(AdapterView<?> parent, View v, int position, long id) { 
         Intent productDetailsIntent = new Intent(ActivityName.this,MenuRestaurantActivity.class);
         startActivity(productDetailsIntent);
     }
 };

答案 2 :(得分:0)

而不是在你的onclick

productDetailsIntent = new Intent(getBaseContext(),MenuRestaurantActivity.class);

使用此行

Intent intent = new Intent(currentActivity.this, NextActivity.class);
startActivity(intent);

在FirstActivity.java文件的onclick按钮中,你应该使用下面的代码。

    Intent i1 = new Intent(firstactivity.this, secondactivity.class);
    i1.putExtra("type", "edit");
   startActivity(i1);

在secondActivity.java文件中创建..使用此代码。

     Bundle extras = getIntent().getExtras();
     Strinjg Value = extras.getSerializable("type").toString();