android应用中,很少有一个activity的app,这次我们设置一个activity,通过listview的点击跳转并显示对应的商店信息。
首先创建类ShopInfoActivity,对应设置其xml文件属性:
java:
public class ShopInfoActivity extends Activity{ @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.activity_shop_info); } }
xml:
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" > <TextView android:id="@+id/tv_text_shop_name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="店名:" android:textSize="20sp"/> </RelativeLayout>
接下来实现点击跳转的:
//意图 Intent it = new Intent(); //跳转activity it.setClass(MainActivity.this, ShopInfoActivity.class); //意图开启 startActivity(it);
在AndroidManifest.xml中注册ShopInfoActivity:
<activity android:name="com.appdemo.eatwhat.ShopInfoActivity"> </activity>
这样,就可以点击跳转到另一个Activity。
时间: 2024-10-10 09:54:29