如果两个活动a b 放你在b的时候返回home,然后按notification在返回时会返回a
我现在想返回b 那么就需要在Intent中添加
Intent notificationIntent = new Intent(this, Main.class);
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
//关键两句
notificationIntent.setAction("android.intent.action.MAIN");
notificationIntent.addCategory("android.intent.category.LAUNCHER");
首先,如果是用simpleCursorAdapter填充ListView的数据时,必须注意sqlite的主键命名,由于simpleCursorAdapter的方法只识别_id,所以,当你用到sqlite的simpleCursorAdapter时,必须把数据表的主键命名为_id。否则就会出现java.lang.IllegalArgumentException: column '_id' does not exist错误。
(1)言归正传,当我们点击ListView时,会调用ListView的点击事件,那么点击的这个item的对应的数据库的_id的值,我们可以通过以下代码获取
public class RoadPickList extends Activity{ private static final String TAG = "RoadPickList"; private ListView lv; private int id; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.roadpicklist); lv = (ListView)findViewById(R.id.listview); /** * 添加点击 */ lv.setOnItemClickListener(new ListView.OnItemClickListener() { public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { // TODO Auto-generated method stub id = (int) arg3;//这里的这个arg3对应的就是数据库中_id的值 } }); }
(2)另外,我们可能还会用到长按菜单(上下文菜单),当我们在ListView上长按时,想获得长按的这个ListView的item的_id的值,参考下面这段代码
/** * 长按菜单的响应 */ public boolean onContextItemSelected(MenuItem aItem) { ContextMenuInfo menuInfo = (ContextMenuInfo) aItem.getMenuInfo(); AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo)aItem.getMenuInfo(); id = (int)info.id;//这里的info.id对应的就是数据库中_id的值 return true; }
<?xml version="1.0" encoding="utf-8"?>
<!-- res/drawable/rounded_edittext.xml -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:padding="10dp">
<solid android:color="#FFFFFF"/>
<corners
android:bottomRightRadius="15dp"
android:bottomLeftRadius="15dp"
android:topLeftRadius="15dp"
android:topRightRadius="15dp"/>
</shape>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dip"
android:background="@drawable/rounded_edittext" />
</LinearLayout>
你也可以设置不同的编辑状态
<?xml version="1.0" encoding="utf-8"?>
<!-- res/drawable/rounded_edittext_states.xml -->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true"
android:state_enabled="true"
android:drawable="@drawable/rounded_focused" />
<item
android:state_focused="true"
android:state_enabled="true"
android:drawable="@drawable/rounded_focused" />
<item
android:state_enabled="true"
android:drawable="@drawable/rounded_edittext" />
</selector>
<?xml version="1.0" encoding="utf-8"?>
<!-- res/drawable/rounded_edittext_focused.xml -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:padding="10dp">
<solid android:color="#FFFFFF"/>
<stroke android:width="2dp" android:color="#FF0000" />
<corners
android:bottomRightRadius="15dp"
android:bottomLeftRadius="15dp"
android:topLeftRadius="15dp"
android:topRightRadius="15dp"/>
</shape>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
android:background="@drawable/rounded_edittext_states"
android:padding="5dip"/>
</LinearLayout>