Android 台灣中文網
標題:
取得spinner item與動態產生連結的按鈕
[打印本頁]
作者:
weiding
時間:
2012-3-7 23:20
標題:
取得spinner item與動態產生連結的按鈕
Hi all
請問要如何去抓到spinner item value?
因為我總是只抓到第一筆資料,
我想應該是我的觀念有錯,
以下是我的部分程式碼。
Spinner spinner_items = (Spinner) findViewById(R.id.job);
ArrayAdapter <CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.jobs,
android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner_items.setAdapter(adapter);
final String jb = (String)spinner_items.getSelectedItem();
另外一個問題是我把SQLite的資料撈出來用 listView 顯示,
要怎麼才可以自動產生一個按鈕去帶出連結,
讓我點擊這連結後就可以去刪除或是修改這檔案,
就是跟Web的方式一樣,
<input type="button" onClick="location.href='action.php?id=1'" />
<input type="button" onClick="location.href='action.php?id=2'" />
然後我可以在action.php透過$_GET來找出資料,
但是要如何在Android上可以run我就沒有頭緒,
請大家幫忙指點迷津,
謝謝。
作者:
george310909
時間:
2012-3-8 12:49
第一個問題的回答--
spinner_items.setOnItemSelectedListener(new Spinner.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,int arg2, long arg3) {
Log.e("Test",mDaysList[arg2]);
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
}
});
複製代碼
你少了監聽事件 arg1 印象中是你點取的View,arg2是你選取到第幾筆資料
其他有一點忘了....
第二個問題的回答--
看起來你想要動態生產元件
layout=(AbsoluteLayout)findViewById(R.id.layout);
adblock=new AdBlock(this,R.drawable.ad);
AbsoluteLayout.LayoutParams rl=new AbsoluteLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, 0, 390);
adblock.setOnClickListener(new View.OnClickListener(){
public void onClick(View arg0){
//點擊事件後要做的事
}
});
layout.addView(adblock,rl);
複製代碼
rl那個變數是設定版面配置
例如元件是Fill_PARENT還是WRAP_CONTENT
至於adblock是我的自製元件
如果我解釋不清楚還請您再細問
作者:
weiding
時間:
2012-3-8 13:34
謝謝,第一個問題我想應該是我JAVA的觀念有點混淆了。第二個問題我會再試試看,謝謝您的幫忙。
歡迎光臨 Android 台灣中文網 (https://apk.tw/)
Powered by Discuz! X3.1