传递arraylist到autocompletetextview的问题

时间:2016-03-29 12:33:18

标签: android android-arrayadapter autocompletetextview

我想在自动完成文本视图下拉列表中显示3个文本视图,所以我正在使用arryalist但是当我将arraylist传递给AutoCompleteTextview时,下拉菜单中没有显示任何内容。 我在logcat中打印arryalist.tostring(),输出是

  

[com.novityrecharge.Beans.AutocompletetextviewGeSe@41097f28]

如何解决这个问题

Autcocompleteadapter2.java

package com.novityrecharge.adapter;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Filter;
import android.widget.TextView;

import com.novityrecharge.Beans.AutocompletetextviewGeSe;
import com.novityrecharge.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by varshils on 3/26/2016.
 */
public class AutoCompleteAdapter2 extends ArrayAdapter<AutocompletetextviewGeSe> {
    private Activity context;
    ArrayList<AutocompletetextviewGeSe> data;
    int layoutResourceId;

    public AutoCompleteAdapter2(Activity context, int resource,ArrayList<AutocompletetextviewGeSe> data)
    {
        super(context, resource, data);
        this.context = context;
        this.data = data;
        this.layoutResourceId = resource;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        return getDropDownView(position, convertView, parent);
    }

    @Override
    public View getDropDownView(int position, View convertView, ViewGroup parent)
    {   // This view starts when we click the spinner.
        View row = convertView;
        listHolder holder = null;
        if(row == null)
        {
            LayoutInflater inflater = ((Activity)context).getLayoutInflater();
            row = inflater.inflate(layoutResourceId, parent, false);

            holder = new listHolder();

            holder.firm = (TextView)row.findViewById(R.id.a_firm);
            holder.mob = (TextView)row.findViewById(R.id.a_mobno);
            holder.mcode = (TextView)row.findViewById(R.id.a_mcode);

            row.setTag(holder);
        }
        else
        {
            holder = (listHolder)row.getTag();
        }
        AutocompletetextviewGeSe item = data.get(position);

        holder.firm.setText(item.getAfirm());
        holder.mob.setText(item.getAmob());
        holder.mcode.setText(item.getAmcode());

        return row;
    }
    static class listHolder
    {
        TextView firm,mob,mcode;
    }
}

Topuptransfer.java

package com.novityrecharge;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.design.widget.TextInputLayout;
import android.support.v4.view.GravityCompat;
import android.support.v7.app.ActionBar;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.EditText;

import com.novityrecharge.Beans.AutocompletetextviewGeSe;
import com.novityrecharge.Beans.ResponseString;
import com.novityrecharge.CrashingReport.ExceptionHandler;
import com.novityrecharge.Interfaces.callback;
import com.novityrecharge.adapter.AutoCompleteAdapter;
import com.novityrecharge.adapter.AutoCompleteAdapter2;
import com.novityrecharge.async.AsyncTaskCommon;
import com.novityrecharge.async.AsynctaskgetBalance;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * Created by varshils on 1/13/2016.
 */
public class TopupTransfer extends BaseActivity{

    AutoCompleteTextView memberView;
    ArrayList <AutocompletetextviewGeSe> name1= null;
    Button btnSubmit;
    String membercode2,amount;
    TextInputLayout smspin_textInputLayout;
    EditText amnt,smspin;;
    HashMap<String,String> memberDetail;
    AutoCompleteAdapter2 adapter;
    DatabaseHelper db;
    int amont;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.topuptransfer);
        if(!(Thread.getDefaultUncaughtExceptionHandler() instanceof ExceptionHandler))
        {
            Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(this));
        }
        ActionBar actionBar = getSupportActionBar();
        assert actionBar != null;
        actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#4CB5F5")));
        db = new DatabaseHelper(TopupTransfer.this);

        memberView = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1);

        name1 = new ArrayList<AutocompletetextviewGeSe>();
        memberDetail = new HashMap<String,String>();
        amnt = (EditText) findViewById(R.id.topup_amnt);
        btnSubmit = (Button) findViewById(R.id.button);
        smspin = (EditText) findViewById(R.id.smspin);
        smspin_textInputLayout = (TextInputLayout) findViewById(R.id.topuptransfer_smspin);

        if(ResponseString.getRequiredSmsPin().equals("TRUE"))
        {
            smspin_textInputLayout.setVisibility(View.VISIBLE);
            smspin.setVisibility(View.VISIBLE);
        }
        else
        {
            smspin_textInputLayout.setVisibility(View.GONE);
            smspin.setVisibility(View.GONE);
        }
        memberView.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

                String text = s.toString();
                Log.d("text", "" + text);

                int len = text.length();
                if (memberView != null)
                {
                if( len >= 3) {
                    Log.d("text", "" + text);
                    try {
                           name1 = GetList2(text);
                           Log.d("ADPTER LIST", name1.toString());
                           adapter = new AutoCompleteAdapter2(TopupTransfer.this,R.layout.autocompletetextview_layout,name1);
                           memberView.setAdapter(adapter);
                        }catch(Exception e){
                            Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(TopupTransfer.this));
                        }
                    }
                }
            }

            @Override
            public void afterTextChanged(Editable s) {
            }
        });

        btnSubmit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {


                if(amnt.getText().toString().length() != 0)
                {
                    amont = Integer.parseInt(amnt.getText().toString());
                }
                if(ResponseString.getRequiredSmsPin().equals("TRUE"))
                {
                    String sms = smspin.getText().toString();
                    String rs = ResponseString.getSmspwd();

                    if (sms.length() == 0) {
                        toastValidationMessage(TopupTransfer.this, getResources().getString(R.string.plsentersmspin));
                        return;
                    }
                    else if (!sms.equals(rs)) {
                        toastValidationMessage(TopupTransfer.this, getResources().getString(R.string.pinentercorrect));
                        return;
                    }
                }else if (memberView.getText().toString().length() == 0) {
                    toastValidationMessage(TopupTransfer.this, getResources().getString(R.string.plsenterfirm));
                    memberView.requestFocus();
                    return;
                }else if (amnt.getText().toString().length() == 0) {
                    toastValidationMessage(TopupTransfer.this, getResources().getString(R.string.plsenteramnt));
                    amnt.requestFocus();
                    return;
                }else if(amont <= 0)
                {
                    toastValidationMessage(TopupTransfer.this, getResources().getString(R.string.plsentercrectamnt));
                    return;
                }
                String Dpattern = memberView.getText().toString();
                membercode2 = BaseActivity.detailMember.get(Dpattern);
                amount = amnt.getText().toString();
                Log.d("topup membercode",membercode2);
                try {

                    if (membercode2 == null) {
                        //Toast.makeText(TopupTransfer.this, "Firm name is not Valid", Toast.LENGTH_SHORT).show();
                        toastValidationMessage(TopupTransfer.this, "Firm name is not Valid");
                        memberView.requestFocus();
                    } else {
                        boolean con = isInternetConnected();
                        if (con) {
                            AsynctaskgetBalance asy = new AsynctaskgetBalance(TopupTransfer.this,new callback(){
                                public void run(String result){
                                    if (ResponseString.getStcode().equals("0")) {
                                        AlertDialog.Builder builder = new AlertDialog.Builder(TopupTransfer.this);
                                        builder.setTitle(R.string.app_name);
                                        builder.setMessage(BaseActivity.sMsg);
                                        builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                                            public void onClick(DialogInterface dialog, int id) {
                                                BaseActivity.sMsg = "";
                                                finish();
                                                Intent m = new Intent(TopupTransfer.this,TopupTransfer.class);
                                                overridePendingTransition(R.anim.pull_in_right, R.anim.push_out_left);
                                                startActivity(m);
                                            }
                                        });
                                        setOnlyBalance();
                                        builder.show();
                                    } else {
                                        toastValidationMessage(TopupTransfer.this,sMsg);
                                    }
                                }

                            } , membercode2,amount,"","BALANCE","DISCOUNT");
                            asy.execute("TopupTransfer");

                        } else {
                            toastValidationMessage(TopupTransfer.this,getResources().getString(R.string.checkinternet));
                        }
                    }
                }catch (Exception e)
                {
                    Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(TopupTransfer.this));
                }
            }
        });

    }
public boolean onCreateOptionsMenu(Menu menu) {
                            MenuInflater inflater = getMenuInflater();
                            inflater.inflate(R.menu.menu_main, menu);
                            return true;
                        }
public boolean onOptionsItemSelected(MenuItem item)
{
    switch (item.getItemId()) {

        case R.id.action_signout:
            logout(TopupTransfer.this);
        default:
            return super.onOptionsItemSelected(item);
        }
}
    @Override
    public void onBackPressed() {
        if (fullLayout != null && fullLayout.isDrawerOpen(GravityCompat.START)) {
            fullLayout.closeDrawer(GravityCompat.START);
        } else {

            Intent intent = new Intent(TopupTransfer.this, HomePage.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(intent);
            finish();
        }
    }
    @Override
    protected void onPause() {
        super.onPause();

        if ((BaseActivity.pleaseWaitDialog != null) && BaseActivity.pleaseWaitDialog.isShowing()) {
            BaseActivity.pleaseWaitDialog.dismiss();
            BaseActivity.pleaseWaitDialog = null;
        }
    }
}

GetList2()

ArrayList<AutocompletetextviewGeSe> GetList2(String text) {
        AutocompletetextviewGeSe autogese;
        ArrayList<AutocompletetextviewGeSe> arrayListtemp = new ArrayList<AutocompletetextviewGeSe>();;
        Cursor cursor = db.getTimeRecordList(text, "ChildUserInfo");
        if (cursor != null){
            if (cursor.moveToFirst()) {
                do {
                    autogese = new AutocompletetextviewGeSe();
                    autogese.setAfirm(cursor.getString(cursor.getColumnIndex("FirmName")));
                    autogese.setAmob(cursor.getString(cursor.getColumnIndex("MobileNumber")));
                    autogese.setAmcode(cursor.getString(cursor.getColumnIndex("MemberCode")));

                    arrayListtemp = new ArrayList<AutocompletetextviewGeSe>();
                    arrayListtemp.add(autogese);

                } while (cursor.moveToNext());
            }
        }
        Log.d("arraylist",arrayListtemp.toString());
        return arrayListtemp;
    }

0 个答案:

没有答案