ListView打开新活动
大家好我的问题是如何使用ListView在新活动中显示水平图像。但是,当我点击列表项目的“ONE”时,它可能会回到主菜单,我已经搜索了同样的问题但它不起作用。我该怎么办? 这是我的MainMenu类
public class MainMenu extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_menu);
}
public void Click(View view){
Intent fors = new Intent(this, ListViewOfMunicipalities.class);
startActivity(fors);
}
MainMenu xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainMenu">
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="ALBAY MABUHAY"
android:id="@+id/button"
android:onClick="Click"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="52dp"
android:background="#51010101"
android:textColor="#ffffff" />
它将转到ListViewOfMunicipalties
public class ListViewOfMunicipalities extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list_view_of_municipalities);
String[] Municipalities = {" Tiwimunicipalitity", "TabacoMunicipality", "MalinaoMunicipality"};
ListAdapter forsAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,Municipalities);
ListView mlistView = (ListView) findViewById(R.id.mlistView);
mlistView.setAdapter(forsAdapter);
mlistView.setOnItemClickListener(
new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
switch( position ) {
case 0: Intent TiwiActivity;
TiwiActivity = new Intent(ListViewOfMunicipalities.this, TiwiMunicipality.class);
startActivity(TiwiActivity);
break;
case 1: Intent TabacoActivity = new Intent(ListViewOfMunicipalities.this, TabacoMunicipality.class);
startActivity(TabacoActivity);
break;
default:
}
}
}
);
}
当我点击案例0时,它将转到TiwiMunicipality.class,当我点击案例1这是TabacoMunicipality.class时,它可能会回到主菜单,这就是错误:(。这是TiwiMunicipality的代码的.class
public class TiwiMunicipality extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tiwi_municipality);
Intent TiwiActivity=new Intent();
setResult(RESULT_OK, TiwiActivity);
//finish();
}
TiwiMunicipality的xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.example.millena.thesisapplication.TiwiMunicipality">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<HorizontalScrollView
android:layout_width="300dp"
android:layout_height="250dp">
<LinearLayout
android:layout_width="350dp"
android:layout_height="250dp">
<ImageView
android:layout_width="300dp"
android:layout_height="250dp"
android:id="@+id/img"
android:background="@mipmap/a" />
<ImageView
android:layout_width="300dp"
android:layout_height="250dp"
android:id="@+id/imageView2"
android:background="@drawable/ganda" />
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
这是TabacoMunicipality.class
public class TabacoMunicipality extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tabaco_municipality);
Intent TabacoActivity=new Intent();
setResult(RESULT_OK, TabacoActivity);
//finish();
}
TabacoMunicipality的xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.example.millena.thesisapplication.TabacoMunicipality">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/TABACO"
android:id="@+id/textView3"
android:layout_gravity="center_horizontal" />
</LinearLayout>
<HorizontalScrollView
android:layout_width="300dp"
android:layout_height="200dp"
android:layout_marginTop="30dp">
<LinearLayout
android:layout_width="300dp"
android:layout_height="200dp">
<ImageView
android:layout_width="300dp"
android:layout_height="200dp"
android:id="@+id/imageView"
android:background="@drawable/ahmm" />
<ImageButton
android:layout_width="300dp"
android:layout_height="200dp"
android:id="@+id/imageButton2"
android:background="@drawable/pogi" />
</LinearLayout>
</HorizontalScrollView>
我的AndroidManifest
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".ListViewOfMunicipalities"
android:label="@string/title_activity_list_view_of_municipalities" >
</activity>
<activity
android:name=".MainMenu"
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=".TiwiMunicipality"
android:label="@string/title_activity_tiwi_municipality" >
<intent-filter>
<action android:name="android.intent.action.TiwiMunicipality" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".TabacoMunicipality"
android:label="@string/title_activity_tabaco_municipality" >
<intent-filter>
<action android:name="android.intent.action.TabacoMunicipality" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".MalinaoMunicipality"
android:label="@string/title_activity_malinao_municipality" >
<intent-filter>
<action android:name="android.intent.action.MalinaoMunicipality" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
我的错误是什么?请帮帮我,因为这是我的论文项目:(