无法在编辑文本android列表视图中输入和编辑值

时间:2016-03-17 09:45:07

标签: android listview arraylist android-edittext

  

我是新的列表视图在android中,我想在列表视图中编辑文本手动输入不同的值,但我能够实现它,任何身体指导我实现它

package com.example.limitscale.beautylog;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Locale;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

public class GiftAdapter extends BaseAdapter {

// Declare Variables
Context context;
LayoutInflater inflater;
ArrayList<HashMap<String, String>> data;
ImageLoader imageLoader;
CheckBox check;
//boolean[] checkBoxState;
private int editingPosition = 0;
ViewHolder viewHolder;
EditText quantity1;
int temp;
int q=0;
public static final String PREFS_NAME = "MyAppSharedPrefs";
HashMap<String, String> resultp = new HashMap<String, String>();

public GiftAdapter(Context context,
                       ArrayList<HashMap<String, String>> arraylist) {
    this.context = context;
    //  checkBoxState=new boolean[arraylist.size()];
    data = arraylist;
    imageLoader = new ImageLoader(context);
}
private class ViewHolder
{
    CheckBox check;
    EditText quantity1;
}
@Override
public int getCount() {
    return data.size();
}

@Override
public Object getItem(int position) {
    return null;
}

@Override
public long getItemId(int position) {
    return 0;
}


public View getView(final int position, View convertView, ViewGroup parent) {
    ViewHolder holder = null;
    temp=position;
    inflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View itemView = inflater.inflate(R.layout.giftadapter, parent, false);

    viewHolder=new ViewHolder();

    resultp = data.get(position);

    final TextView country = (TextView) itemView.findViewById(R.id.product);
    final  TextView population = (TextView) itemView.findViewById(R.id.price);
    quantity1 = (EditText) itemView.findViewById(R.id.quantity);
    quantity1.addTextChangedListener(new TextWatcher() {

        @Override
        public void afterTextChanged(Editable arg0) {
            // TODO Auto-generated method stub
            String charText = quantity1.getText().toString().toLowerCase(Locale.getDefault());

            charText = charText.toLowerCase(Locale.getDefault());

        }

        @Override
        public void beforeTextChanged(CharSequence arg0, int arg1,
                                      int arg2, int arg3) {
            // TODO Auto-generated method stub
        }

        @Override
        public void onTextChanged(CharSequence arg0, int arg1, int arg2,
                                  int arg3) {
            // TODO Auto-generated method stub
        }
    });

    final  ImageView flag = (ImageView) itemView.findViewById(R.id.image);
    final LinearLayout content = (LinearLayout) itemView.findViewById(R.id.content);
    ImageButton add_ = (ImageButton) itemView.findViewById(R.id.ad_01);

    final String quan = quantity1.getText().toString();
    country.setText(resultp.get(Giftafriend.COUNTRY));
    population.setText(resultp.get(Giftafriend.POPULATION));
    imageLoader.DisplayImage(resultp.get(Giftafriend.FLAG), flag);

    add_.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            content.setBackgroundColor(0xFFEDD3F6);

            resultp = data.get(position);
            SharedPreferences settings = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
            SharedPreferences.Editor editor = settings.edit();
            editor.putString("addservice", resultp.get(Giftafriend.COUNTRY));
            editor.putString("addprice", resultp.get(Giftafriend.POPULATION));
            editor.commit();
            ((MainActivity) context).showAdd1((resultp.get(position)));

        }
    });

    return itemView;
}}

enter image description here

  

我希望我的输出像这样,但我的编辑文本不允许我更改其中的值。它显示值0,这是我在xml中给出的提示。

gift adapter.xml

<?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="80dp"
android:orientation="horizontal"
android:descendantFocusability="blocksDescendants"
android:checkMark="?android:attr/listChoiceIndicatorMultiple"
android:id="@+id/listrow">

<ImageView
    android:layout_width="80dp"
    android:layout_height="80dp"
    android:scaleType="fitXY"
    android:id="@+id/image" />

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:id="@+id/content">

    <LinearLayout
        android:layout_weight="1"
        android:layout_width="wrap_content"
        android:layout_height="80dp"
        android:orientation="vertical">
        <TextView
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:id="@+id/product"
            android:textStyle="bold"
            android:textSize="16dp"
            android:paddingLeft="10dp"
            android:paddingTop="10dp"
            android:hint="Title"
            />

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="40dp"
            android:orientation="horizontal">
            <TextView
                android:layout_width="match_parent"
                android:layout_height="40dp"
                android:textSize="16dp"
                android:paddingTop="10dp"
                android:text="Rs"
                android:layout_marginLeft="12dp"
                />
            <TextView
                android:layout_width="match_parent"
                android:layout_height="40dp"
                android:id="@+id/price"
                android:textSize="16dp"
                android:layout_marginLeft="2dp"
                android:paddingLeft="4dp"
                android:paddingTop="10dp"
                android:hint="price"
                />
        </LinearLayout>
    </LinearLayout>
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:orientation="horizontal">


        <EditText
            android:layout_weight="1"
            android:id="@+id/quantity"
            android:layout_width="50dp"
            android:gravity="center"
            android:hint="0"
            android:textColor="@color/blue"
            android:textColorHint="@color/blue"
            android:layout_marginRight="4dp"
            android:layout_marginTop="25dp"
            android:textSize="16dp"
            android:background="@drawable/boxborder"
            android:layout_height="30dp" />

        <ImageButton
            android:id="@+id/ad_01"
            android:layout_weight="1"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:textSize="20dip"
            android:layout_marginRight="8dp"
            android:text="+"
            android:layout_marginTop="20dp"
            android:textColor="#000000"
            android:background="@drawable/cart"/>
    </LinearLayout>
</LinearLayout>

2 个答案:

答案 0 :(得分:0)

尝试从适配器项目布局中删除android:descendantFocusability="blocksDescendants"

答案 1 :(得分:0)

请将android:强文 editable = true添加到您的编辑文本

   <EditText
            android:id="@+id/quantity"
            android:layout_width="50dp"
            android:layout_height="80dp"
            android:layout_weight="1"
            android:gravity="center"
            android:hint="0"
            **android:editable="true"**
            android:textColor="#eaedfe" />