android EditText字段不允许用户输入listView

问题描述 投票:0回答:1
Single_row_layout:

<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="5dp" > <TextView android:id="@+id/pizzaname" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:paddingLeft="8dp" android:textSize="18sp" android:textStyle="bold" android:hint="nome_pizza" android:layout_centerVertical="true"/> <TextView android:id="@+id/pizzaprice" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toLeftOf="@+id/editTextQuantity" android:textSize="18sp" android:textStyle="bold" android:hint="prezzo" android:layout_centerVertical="true" /> <Button android:layout_width="50sp" android:layout_height="wrap_content" android:id="@+id/ib_addnew" android:layout_gravity="bottom" android:hint="+" android:layout_toLeftOf="@+id/ib_remove" android:background="#00ffffff" /> <EditText android:layout_width="50dp" android:layout_height="48dp" android:text="0" android:id="@+id/editTextQuantity" android:layout_toLeftOf="@+id/ib_addnew" android:textAlignment="center" android:inputType="numberDecimal" /> <Button android:layout_width="50sp" android:layout_height="wrap_content" android:id="@+id/ib_remove" android:hint="-" android:layout_marginRight="5sp" android:layout_alignParentRight="true" android:background="#00ffffff" /> </RelativeLayout>

主要活动中的代码(称为菜单),其中我设置了适配器

Concreate:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.menu_layout);
    Intent i = getIntent();

    order = new Order();
    Server server = StubServer.getIstance(this);

    pizzaNames = server.getPizzaNames();
    pizzaPrices = server.getPizzaPrices();

    if(i.getBooleanExtra("session",false)){
        order=(Order)i.getSerializableExtra("order");
    }

    listView = (ListView) findViewById(R.id.mylist);
    listAdapter = new ListAdapter(this, pizzaNames, pizzaPrices,order.pizzaQuantity);

    listView.setAdapter(listAdapter);
    listAdapter.setCustomButtonListener(this);


}

这是listAdapter

构造者:

public ListAdapter(Context context, String[] listViewItems,String[] prices,ArrayList<Integer> q) {
    this.context = context;
    this.listViewItems = listViewItems;
    this.prices=prices;
    this.quantity=q;

    if(quantity.size()==0) {
        for (int i = 0; i < listViewItems.length; i++) {
           quantity.add(0);
        }
    }
}

GETVIEW方法:

@Override public View getView(final int position, View convertView, ViewGroup parent) { View row; final ListViewHolder listViewHolder; if(convertView == null) { LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); row = layoutInflater.inflate(R.layout.activity_custom_listview,parent,false); listViewHolder = new ListViewHolder(); listViewHolder.pizzaName = (TextView) row.findViewById(R.id.pizzaname); listViewHolder.price=(TextView) row.findViewById(R.id.pizzaprice); listViewHolder.btnPlus = (Button) row.findViewById(R.id.ib_addnew); listViewHolder.edTextQuantity = (EditText) row.findViewById(R.id.editTextQuantity); listViewHolder.btnMinus = (Button) row.findViewById(R.id.ib_remove); row.setTag(listViewHolder); } else { row=convertView; listViewHolder= (ListViewHolder) row.getTag(); } try{ //HashMap<String, String> map = listQuantity.get(position); //quantity[position]+"" listViewHolder.edTextQuantity.setText(quantity.get(position)+""); //holder.item_name.setText(map.get("name")); //holder.order_qty.setText(map.get("quantity")); //Log.v("Available or not", ""+map.get("available")); }catch(Exception e){ e.printStackTrace(); } listViewHolder.btnPlus.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (customButtonListener != null) { customButtonListener.onButtonClickListener(position, listViewHolder.edTextQuantity, 1); int tmp=quantity.get(position); quantity.set(position,tmp+1); //quantity[position]=[position]+1; } } }); //listViewHolder.edTextQuantity.setText("0"); listViewHolder.btnMinus.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (customButtonListener != null) { customButtonListener.onButtonClickListener(position,listViewHolder.edTextQuantity,-1); if(quantity.get(position)>0) quantity.set(position, quantity.get(position) - 1); } } }); listViewHolder.pizzaName.setText(listViewItems[position]); listViewHolder.price.setText(prices[position]); if(position%2==0){ row.setBackgroundColor(Color.LTGRAY); } return row; }

最终,这里有两个应用程序屏幕截图

刚开始活动

在第一行Edittext字段上点击之后

提前感谢您。

在您的适配器更改代码如下

try{ listViewHolder.edTextQuantity.setText(String.valueOf(quantity.get(position))); //holder.item_name.setText(map.get("name")); //holder.order_qty.setText(map.get("quantity")); //Log.v("Available or not", ""+map.get("available")); }catch(Exception e){ e.printStackTrace(); }

listViewHolder.btnPlus.setOnClickListener(new View.OnClickListener() { @Override public void onClick (View v){ if (customButtonListener != null) { customButtonListener.onButtonClickListener(position, listViewHolder.edTextQuantity, 1); int tmp = Integer.parseInt(listViewHolder.edTextQuantity.gettext().tostring()) quantity.set(position, tmp + 1); //quantity[position]=[position]+1; listViewHolder.edTextQuantity.settext(String.valueOf(temp + 1)); } } } ); //listViewHolder.edTextQuantity.setText("0"); listViewHolder.btnMinus.setOnClickListener(new View.OnClickListener() { @Override public void onClick (View v){ if (customButtonListener != null) { customButtonListener.onButtonClickListener(position, listViewHolder.edTextQuantity, -1); if (quantity.get(position) > 0) int tmp = Integer.parseInt(listViewHolder.edTextQuantity.gettext().tostring()) quantity.set(position, tmp - 1); //quantity[position]=[position]+1; listViewHolder.edTextQuantity.settext(String.valueOf(temp - 1)); } } } ); listViewHolder.pizzaName.setText(listViewItems[position]); listViewHolder.price.setText(prices[position]); if(position%2==0) { row.setBackgroundColor(Color.LTGRAY); }
android listview android-edittext
1个回答
0
投票

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.