android的listview item點擊詳解
package
com.wps.android;
import
java.util.ArrayList;
import
android.app.Activity;
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;
public
class
Layouts
extends
Activity {
/** Called when the activity is first created. */
private
ListView mylistview;
private
ArrayList<String> list =
new
ArrayList<String>();
@Override
public
void
onCreate(Bundle savedInstanceState) {
super
.onCreate(savedInstanceState);
setContentView(R.layout.main);
mylistview = (ListView)findViewById(R.id.listview);
list.add(
"LinearLayout"
);
list.add(
"AbsoluteLayout"
);
list.add(
"TableLayout"
);
list.add(
"RelativeLayout"
);
list.add(
"FrameLayout"
);
ArrayAdapter<String> myArrayAdapter =
new
ArrayAdapter<String>
(
this
,android.R.layout.simple_list_item_1,list);
mylistview.setAdapter(myArrayAdapter);
/*mylistview.setOnTouchListener(new OnTouchListener(){
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
if(event.getAction() == MotionEvent.ACTION_DOWN)
{
mylistview.setBackgroundColor(Color.BLUE);
}
return false;
}
});*/
mylistview.setOnItemClickListener(
new
OnItemClickListener(){
@Override
public
void
onItemClick(AdapterView<?> arg0, View arg1,
int
arg2,
long
arg3) {
// TODO Auto-generated method stub
if
(list.get(arg2).equals(
"LinearLayout"
))
{
Intent intent =
new
Intent(
"com.wps.android.LINEARLAYOUT"
);
startActivity(intent);
}
if
(list.get(arg2).equals(
"AbsoluteLayout"
))
{
Intent intent =
new
Intent(
"com.wps.android.ABSOLUTELAYOUT"
);
startActivity(intent);
}
if
(list.get(arg2).equals(
"TableLayout"
))
{
Intent intent =
new
Intent(
"com.wps.android.TABLELAYOUT"
);
startActivity(intent);
}
if
(list.get(arg2).equals(
"RelativeLayout"
))
{
Intent intent =
new
Intent(
"com.wps.android.RELATIVELAYOUT"
);
startActivity(intent);
}
if
(list.get(arg2).equals(
"FrameLayout"
))
{
Intent intent =
new
Intent(
"com.wps.android.FRAMELAYOUT"
);
startActivity(intent);
}
}
});
}
}
最後更新:2017-04-03 12:54:02
上一篇:
linux驅動開發--copy_to_user 、copy_from_user函數實現內核空間數據與用戶空間數據的相互訪問
下一篇:
Android 通過包名打開App的代碼
Ubuntu linux解決:”修改profile/enviroment文件無法進入ubuntu“的方法
《JVM故障診斷指南》之3 —— Java 線程: JVM持有內存的分析
ORACLE 官方文檔
Oracle 12c ASM 防範異常的恢複增強
對安卓係統的功能性升級來說,安全補丁更重要!
道旅鬼穀子分享:如何打好業務監控的組合拳
Java多線程問題總結(下)
C# WinForm多線程開發(二) ThreadPool 與 Timer
撿到iPhone7怎麼解鎖?蘋果6splus解鎖密碼忘記導致手機被鎖定該怎麼辦
《8051係列單片機C程序設計完全手冊》的電子書PDF完整合集版