activity调用,Listview,自定义标题栏
1 //MainActivity.java 主调activity 2 package com.example.secondweek; 3 import android.os.Bundle; 4 import android.app.Activity; 5 import android.content.Intent; 6 import android.view.Menu; 7 import android.view.View; 8 import android.view.View.OnClickListener; 9 import android.view.Window; 10 import android.widget.*; 11 public class MainActivity extends Activity { 12 private ImageButton button_save; 13 private EditText edittext; 14 @Override 15 protected void onCreate(Bundle savedInstanceState) { 16 super.onCreate(savedInstanceState); 17 requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); 18 setContentView(R.layout.activity_main); 19 getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.title_of_main); 20 edittext=(EditText)findViewById(R.id.edit_text); 21 edittext.setOnClickListener(new OnClickListener() { 22 23 @Override 24 public void onClick(View arg0) { 25 // TODO Auto-generated method stub 26 edittext.setText(""); 27 } 28 }); 29 button_save=(ImageButton)findViewById(R.id.store); 30 button_save.setOnClickListener(new OnClickListener() { 31 32 @Override 33 public void onClick(View arg0) { 34 // TODO Auto-generated method stub 35 String str=edittext.getText().toString(); 36 String[] str_array=str.split("\n"); 37 Intent intent=new Intent(); 38 intent.setClass(MainActivity.this, SecondActivity.class); 39 Bundle bundel=new Bundle(); 40 bundel.putStringArray("1", str_array); 41 intent.putExtras(bundel); 42 startActivity(intent); 43 } 44 }); 45 } 46 }
1 //SecondActivity.java 被掉activity 2 package com.example.secondweek; 3 import java.util.ArrayList; 4 import java.util.List; 5 6 import android.os.Bundle; 7 import android.app.Activity; 8 import android.view.ContextMenu; 9 import android.view.Menu; 10 import android.view.View; 11 import android.view.ContextMenu.ContextMenuInfo; 12 import android.view.View.OnClickListener; 13 import android.view.View.OnCreateContextMenuListener; 14 import android.view.Window; 15 import android.widget.*; 16 import android.widget.AdapterView.OnItemClickListener; 17 public class SecondActivity extends Activity{ 18 private ListView listview; 19 public String[] str_array; 20 @Override 21 protected void onCreate(Bundle savedInstanceState) { 22 // TODO Auto-generated method stub 23 super.onCreate(savedInstanceState); 24 requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); 25 setContentView(R.layout.activity_second); 26 getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_of_second); 27 str_array=this.getIntent().getExtras().getStringArray("1"); 28 listview=(ListView)findViewById(R.id.listview); 29 List<String> list_string=new ArrayList<String>(); 30 for(int i=0;i<str_array.length;i++) 31 list_string.add(str_array[i]); 32 listview.setAdapter(new ArrayAdapter<String>(getApplicationContext(),android.R.layout.simple_list_item_single_choice,list_string)); 33 listview.setItemsCanFocus(false); 34 listview.setOnItemClickListener(new OnItemClickListener() { 35 public void onItemClick(AdapterView<?> adapter, View view, int position,long row_num) { 36 (Toast.makeText(getApplicationContext(),"你点击了第"+(position+1)+"项,内容为:"+str_array[position],Toast.LENGTH_SHORT)).show(); 37 } 38 }); 39 } 40 }
1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 xmlns:tools="http://schemas.android.com/tools" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 android:orientation="vertical" 6 tools:context=".MainActivity" > 7 <EditText 8 android:id="@+id/edit_text" 9 android:layout_width="match_parent" 10 android:layout_height="match_parent" 11 android:gravity="start" 12 android:scrollbars="vertical" 13 android:text="@string/text_of_edit"/> 14 15 </LinearLayout>
1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 android:orientation="vertical"> 6 <ListView 7 android:layout_width="match_parent" 8 android:layout_height="match_parent" 9 android:scrollbars="vertical" 10 android:dividerHeight="4dp" 11 android:id="@+id/listview"></ListView> 12 </LinearLayout>
1 <?xml version="1.0" encoding="utf-8"?> 2 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 android:layout_width="match_parent" 4 android:layout_height="wrap_content" 5 style="@style/title_of_main"> 6 <TextView 7 android:text="@string/text_of_title_of_main" 8 android:layout_height="match_parent" 9 android:layout_width="wrap_content" 10 android:gravity="center" 11 android:layout_alignParentLeft="true" 12 android:layout_alignParentTop="true" 13 android:layout_alignParentBottom="true"/> 14 <ImageButton 15 android:id="@+id/store" 16 android:layout_height="fill_parent" 17 android:layout_width="60dp" 18 android:layout_alignParentRight="true" 19 android:src="@drawable/store" 20 android:scaleType="fitXY"/> 21 22 </RelativeLayout>
1 <?xml version="1.0" encoding="utf-8"?> 2 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 android:layout_width="match_parent" 4 android:layout_height="wrap_content" 5 style="@style/title_of_main" > 6 <ImageView 7 android:id="@+id/image_view" 8 android:layout_width="wrap_content" 9 android:layout_height="match_parent" 10 android:scaleType="fitCenter" 11 android:src="@drawable/ic_launcher"/> 12 13 <TextView 14 android:layout_width="wrap_content" 15 android:layout_height="match_parent" 16 android:layout_alignParentTop="true" 17 android:layout_toRightOf="@+id/image_view" 18 android:gravity="center" 19 android:text="@string/text_of_second" 20 android:textSize="25sp" /> 21 22 </RelativeLayout>
1 <?xml version="1.0" encoding="utf-8"?> 2 <manifest xmlns:android="http://schemas.android.com/apk/res/android" 3 package="com.example.secondweek" 4 android:versionCode="1" 5 android:versionName="1.0" > 6 7 <uses-sdk 8 android:minSdkVersion="14" 9 android:targetSdkVersion="19" /> 10 11 <application 12 android:allowBackup="true" 13 android:icon="@drawable/ic_launcher" 14 android:label="@string/app_name" 15 android:theme="@style/title_of_main" > 16 <activity 17 android:name="com.example.secondweek.MainActivity" 18 android:label="@string/app_name" > 19 <intent-filter> 20 <action android:name="android.intent.action.MAIN" /> 21 22 <category android:name="android.intent.category.LAUNCHER" /> 23 </intent-filter> 24 </activity> 25 <activity 26 android:name="com.example.secondweek.SecondActivity"> 27 28 </activity> 29 </application> 30 31 </manifest>

浙公网安备 33010602011771号