1
我製作了一個滑塊,參考this教程。我做了一些改變。我爲每個圖像添加了一個微調器和一個editText,以便用戶可以輸入內容並選擇提供的選項。從Spinner獲取選定的值
我Acitvity是這樣的:
public class Details extends Activity{
...
...
@Override
protected void onCreate(Bundle savedInstanceState) {
session = new SessionMngr(getApplicationContext());
cart = new ShoppingCart(getApplicationContext());
uid = session.getIntValues("uid");
selectedItems = new ArrayList<String>();
super.onCreate(savedInstanceState);
setContentView(R.layout.details);
selectedItems = cart.getCartImages();
viewPager = (ViewPager) findViewById(R.id.pager);
Intent i = getIntent();
int position = i.getIntExtra("position", 0);
adapter = new FullScreenImageAdapter(Details.this, selectedItems);
viewPager.setAdapter(adapter);
viewPager.setCurrentItem(position);
}
@Override
public boolean onCreateOptionsMenu(Menu menu){
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.details_action_bar, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
nvpSizes = new ArrayList<NameValuePair>();
for(int i=0;i<selectedItems.size();i++){
nvpSizes.add(new BasicNameValuePair("1", "1")); //qty , sizeId
}
switch(item.getItemId()){
case R.id.action_check_out:
dialog = ProgressDialog.show(this, "", "Please wait. Uploading file...",true);
new Thread(new Runnable(){
public void run(){
UploadFile(selectedItems, nvpSizes);
}
}).start();
break;
case R.id.action_add_more:
// I want to get the Scanner value and editText value of all the scanners and editTexts here
Intent intent = new Intent(Details.this, Dashboard.class);
startActivity(intent);
break;
default:
break;
}
return super.onOptionsItemSelected(item);
}
...
...
}
我FullScreenImageAdapter是這樣的:
public class FullScreenImageAdapter extends PagerAdapter {
public FullScreenImageAdapter(Activity activity,
ArrayList<String> imagePaths) {
this._activity = activity;
this.context = _activity.getApplicationContext();
this._imagePaths = imagePaths;
}
...
...
@Override
public Object instantiateItem(ViewGroup container, int position) {
ImageView imgDisplay;
inflater = (LayoutInflater) _activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View viewLayout = inflater.inflate(R.layout.layout_fullscreen_image, container,
false);
imgDisplay = (ImageView) viewLayout.findViewById(R.id.imgDisplay);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this._activity,
android.R.layout.simple_spinner_item, sizes);
Spinner mSpinner = (Spinner) viewLayout.findViewById(R.id.sizes);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mSpinner.setAdapter(adapter);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
Bitmap bitmap = BitmapFactory.decodeFile(_imagePaths.get(position), options);
imgDisplay.setImageBitmap(bitmap);
((ViewPager) container).addView(viewLayout);
return viewLayout;
}
...
...
}
我的活動在操作欄和按鈕上點擊我要訪問的兩個按鈕所有微調和編輯文本的信息。我不知道得到它。我試過它:
Spinner mSpinner = (Spinner) viewLayout.findViewById(R.id.sizes);
mSpinner.getSelectedItem();
但上述代碼只返回一個值。 我如何獲得所有設置的微調器。
我怎樣才能得到每個微調的價值? – Robz
看到編輯答案 –
我想你誤解了我的問題。我有多個Spinners不是多個Spinner值。具有微調器的佈局被調用爲ListView,所以問題是所有的微調器都有相同的ID。並且我想要從所有微調器獲得值 – Robz