0

我正在使用自定义数组适配器来显示一些产品的列表。在列表视图中有两个文本视图和一个编辑文本。当我单击它输入值时,编辑文本会集中在多个文本字段中。

我没有遇到实际问题。试了好几天了,请帮帮我。

<?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/txtBP"
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:gravity="center_vertical|center_horizontal"
        android:textColor="#000000"
        android:textSize="15sp" />


    <TextView
        android:id="@+id/txtMRP"
        android:layout_width="match_parent"`enter code here`
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:gravity="center_vertical|center_horizontal"
        android:textColor="#000000"
        android:textSize="15sp" />


    <EditText
        android:id="@+id/qty"
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:gravity="center_vertical|center_horizontal"
        android:hint="@string/texthint"
        android:inputType="number"
        android:maxLength="3" />

    </LinearLayout>


package com.example.order;

import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.TextView;

    public class ModifiedAdapter extends BaseAdapter{

    Context context;
    int layoutResourceId;   
    Order data[] = null;`enter code here`

    public ModifiedAdapter(Context context, int layoutResourceId, Order[] data) {
        this.layoutResourceId = layoutResourceId;
        this.context = context;
        this.data = data;
    }



    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
       // View row = convertView;
        OrderHolder holder = null;

        if(convertView == null)
        {
            LayoutInflater inflater = ((Activity)context).getLayoutInflater();
            convertView = inflater.inflate(layoutResourceId, parent, false);

            holder = new OrderHolder();
            holder.txtBP = (TextView)convertView.findViewById(R.id.txtBP);
            holder.txtMRP = (TextView)convertView.findViewById(R.id.txtMRP);
            holder.qty = (EditText)convertView.findViewById(R.id.qty);

            convertView.setTag(holder);
        }
        else
        {
            holder = (OrderHolder)convertView.getTag();
        }

        Order order = data[position];
        holder.txtBP.setText(order.BP);
        holder.txtMRP.setText(order.MRP);

        Log.d("data count : ", ""+getCount());

        return convertView;
    }


@Override
public int getCount() {
    // TODO Auto-generated method stub
    return data.length;
}

@Override
public Object getItem(int arg0) {
    // TODO Auto-generated method stub
    return arg0;
}

@Override
public long getItemId(int arg0) {
    // TODO Auto-generated method stub
    return arg0;
}


static class OrderHolder
{
    TextView txtMRP;
    TextView txtBP;
    EditText qty;
}


}

上面提到的是我正在使用的 xml 和适配器 :) 而且我没有收到任何错误。

4

1 回答 1

0

替换你的 XML 并检查并告诉我

<TextView
    android:id="@+id/txtBP"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:layout_weight="1"
    android:gravity="center_vertical|center_horizontal"
    android:textColor="#000000"
    android:textSize="15sp" />

<TextView
    android:id="@+id/txtMRP"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:layout_weight="1"
    android:gravity="center_vertical|center_horizontal"
    android:textColor="#000000"
    android:textSize="15sp" />

<LinearLayout
    android:id="@+id/qtyLayout"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:layout_weight="1"
     android:focusable="true" 
    android:focusableInTouchMode="true"  
    android:gravity="center_vertical|center_horizontal" >

    <EditText
        android:id="@+id/qty"
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:gravity="center_vertical|center_horizontal"
        android:hint="@string/texthint"
        android:inputType="number"
        android:maxLength="3" />
</LinearLayout>

于 2012-12-10T12:31:54.060 回答