世界,你好:獲取項目名稱
我又需要你的幫助,我有onclick事件的列表視圖,但我需要從被點擊項目獲得項目名稱。
這是我此刻...
Product_listview.setOnItemClickListener(new AdapterView.OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,long id) {
final int selected_row = position;
final Product user = (Product) parent.getItemAtPosition(position);
AlertDialog.Builder alert = new AlertDialog.Builder(nuevo_pedido.this);
alert.setTitle("Cantidad: ");
final NumberPicker np = new NumberPicker(nuevo_pedido.this);
String[] nums = new String[11];
for(int i=0; i<nums.length; i++)
nums[i] = Integer.toString(i);
np.setMinValue(0);
np.setMaxValue(nums.length-1);
np.setWrapSelectorWheel(false);
np.setDisplayedValues(nums);
np.setValue(0);
alert.setView(np);
alert.setPositiveButton("Aceptar", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Do something with value!
int valor = np.getValue();
Toast.makeText(getApplicationContext(), "Valor: " + valor + " Producto: " + user + " Usr: " + extraData, Toast.LENGTH_SHORT).show();
}
});
alert.setNegativeButton("Cancelar", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
});
alert.show();
}
});
當我的代碼運行它的一切OK,但送東西究竟是不是名字。
建議?
他已經在使用它。問題是他試圖將他的「產品」對象顯示爲字符串 – dymmeh
該代碼發送相同的結果... [email protected] – bigmerol