1

こんにちは、皆さんが提案したいくつかの異なるコードを試してみて失敗した後、コードの動作方法を変更しました。これで、メイン画面に 3 つのリスト項目があり、3 つの異なるアクティビティを呼び出す必要があります。私が何をしても、これはうまくいきません。2013 年 7 月 3 日更新 - すべての返信に感謝します。私が抱えていた問題を整理しました。いくつかのマイナーな調整とその動作。もう一度助けて乾杯..

私の主な活動

package com.example.mechanicalengineering;


 import android.app.Activity;
 import android.app.ListActivity;
 import android.content.Intent;
  import android.os.Bundle;
 import android.view.View;
 import android.widget.AdapterView;
 import android.widget.AdapterView.OnItemClickListener;
 import android.widget.ArrayAdapter;
 import android.widget.ListView;
 import android.widget.TextView;


 public class HomeList extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_home_list);

  String[] homelist = getResources().getStringArray(R.array.HomePageList);
  setListAdapter(new ArrayAdapter<String>(this, R.layout.activity_home_list,    homelist));

TextView LV = getListView();
  LV.setTextFilterEnabled(true);

 LV.setOnItemClickListener(new OnItemClickListener() {
    public void onItemClick(AdapterView<?> parent, View view,
      int position, long id) {
        Intent myIntent = null;

         if(((TextView) view).getText().equals("Material Properties - Metal")){
          myIntent = new Intent(view.getContext(), MetalList.class);
          }

           if(((TextView) view).getText().equals("Material Properties - Plastic")){
            myIntent = new Intent(view.getContext(), PlasticList.class);
           }

           if(((TextView) view).getText().equals("Material Properties - Other")){
            myIntent = new Intent(view.getContext(), OtherList.class);
          }

                       startActivity(myIntent);
    }
  });
 }

}

私の2番目の活動

package com.example.mechanicalengineering;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class MetalList extends Activity {

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


}

res/layout の acivity_home_list.xml ファイル

<RelativeLayout xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".HomeList" >

<ListView
    android:id="@+id/HomePageList"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:entries="@array/HomePageList" >

</ListView>

</RelativeLayout>

res/values 内の strings.xml ファイル

<?xml version="1.0" encoding="utf-8"?>
<resources>

<string name="app_name">Mechanical Engineering</string>
<string name="hello_world">Hello world!</string>
<string name="menu_settings">Settings</string>
<string name="title_activity_metal_list">MetalList</string>

<string-array name="HomePageList">
    <item>Material Properties - Metal</item>
<item>Material Properties - Plastic</item>
<item>Material Properties - Other</item>

</string-array>

<color name="divideline">#3f3f3f</color>

<string name="title_activity_plastic_list">Plastic Properties</string>
<string name="title_activity_other_list">Other Properties</string>

</resources>

マニフェスト ファイル

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mechanicalengineering"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.mechanicalengineering.HomeList"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.example.mechanicalengineering.MetalList"
        android:label="@string/title_activity_metal_list" >
    </activity>
    <activity
        android:name="com.example.mechanicalengineering.PlasticList"
        android:label="@string/title_activity_plastic_list" >
    </activity>
    <activity
        android:name="com.example.mechanicalengineering.OtherList"
        android:label="@string/title_activity_other_list" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    </application>

 </manifest>
4

2 に答える 2

0

ちょっとこれをしてください。

       ListView lv=(ListView)findViewById(R.id.HomePageList);

       lv.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                long arg3) {
                     Intent newwin = new Intent(context, MetalList.class);
                     startActivity(newwin);

        }}
于 2013-02-19T11:03:21.383 に答える
0

これを試して。ホームリストにアイテムを追加する必要があります

import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
public class HomeList extends Activity implements OnItemSelectedListener{

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

   @Override
   public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
        long arg3) {
           //add check if item is the one you need
           Intent intent = new Intent( new Intent(this, MetalList.class);
       startActivity(intent);
   }

   @Override
   public void onNothingSelected(AdapterView<?> arg0) {
    // TODO Auto-generated method stub  
   }
 }
于 2013-02-19T10:27:34.443 に答える