除了listview之外,所有内容都显示在对话框内

时间:2017-11-29 09:13:32

标签: android listview android-dialogfragment android-dialog

我正在尝试使用带有列表视图的edittext来从自定义列表视图中选择联系人这里是代码,但除了列表视图外,所有内容都会显示:

InstantDialogBox:

public class InstantTextBoxDialog extends DialogFragment {
private EditText message;
private Button sendToAll;
private Button sendToLimited;
private ListView listContacts;
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

   AlertDialog.Builder builder=new AlertDialog.Builder(getActivity());

    LayoutInflater inflater=getActivity().getLayoutInflater();

     View view=inflater.inflate(R.layout.intant_message,null,false);




    message=(EditText)view.findViewById(R.id.instant_message);
    sendToAll=(Button) view.findViewById(R.id.btn_sent_to_all);
    listContacts=(ListView)view.findViewById(R.id.list_checkable);
    ChackableListAdapter adapter=new ChackableListAdapter(getActivity(),R.layout.list_chackable_item,new ArrayList<Contact>());

    sendToAll.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if(!TextUtils.isEmpty(message.getText())){

                ChatService.bind.getService().sendMessageToAll(message.getText().toString());
                message.setText("");
                dismiss();
            }

        }
    });

    sendToLimited=(Button) view.findViewById(R.id.btn_send_to_limited);

    sendToLimited.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if(!TextUtils.isEmpty(message.getText())){



            }

        }
    });
    listContacts.setAdapter(adapter);

    builder.setView(view);

    return builder.create();
}

CheckableListAdapter:

public class ChackableListAdapter extends ArrayAdapter<Contact> {


private ArrayList<Contact> contacts;
private int resource;
private Context context;
private ArrayList<Contact> choosen;


public ChackableListAdapter(@NonNull Context context, int resource,ArrayList<Contact> arrayList) {
    super(context, resource,arrayList);
    this.context=context;
    this.resource=resource;
    this.contacts=arrayList;
    contacts= DatabaseHandler.getDataBaseHandler(context).getAllRegisteredContacts();
    choosen=new ArrayList<>();
}


@Nullable
@Override
public Contact getItem(int position) {
    return contacts.get(position);
}

@NonNull
@Override
public View getView(final int position, @Nullable View view, @NonNull ViewGroup parent) {
        Holder holder=null;
    if (view == null || view.getTag() == null) {
        holder=new Holder();
        view= LayoutInflater.from(context).inflate(resource,null);
        holder.phone=(TextView)view.findViewById(R.id.text_number);
        holder.name=(CheckBox)view.findViewById(R.id.checkbox_number);
        view.setTag(holder);
    }
    else {
        holder = (Holder) view.getTag();
    }
    holder.phone.setText(getItem(position).phone_number);
    holder.name.setText(getItem(position).name);

    holder.name.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if(isChecked){
               choosen.add(getItem(position));
            }else {
                int i=0;
                for (Contact contact:choosen){

                    if(contact.phone_number.equalsIgnoreCase(getItem(position).phone_number)){
                              choosen.remove(i);
                              notifyDataSetChanged();
                    }
                    i++;
                }
            }
        }
    });

    Log.wtf("generating rows"," yes");

    return view;
}



private class Holder{
    public CheckBox name;
    public TextView phone;



}


public ArrayList<Contact> getChoosenContacts(){
    return choosen;
}
}

intant_message.xml:

<?xml version="1.0" encoding="utf-8"?>

<EditText
    android:id="@+id/instant_message"
    android:layout_width="wrap_content"
    android:layout_height="100dp"
    android:layout_weight="5"
    android:gravity="top"
    />
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        <Button
            android:id="@+id/btn_send_to_limited"
            android:text="send to limited"
            android:layout_width="95dp"
            android:textSize="10sp"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            />

        <Button
            android:id="@+id/btn_sent_to_all"
            android:layout_width="95dp"
            android:layout_height="wrap_content"
            android:text="send to all"
            android:textSize="10sp"
            android:layout_below="@+id/btn_send_to_limited"
            android:layout_marginTop="5dp"
            />
    </LinearLayout>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    xmlns:tools="http://schemas.android.com/tools">


    <ListView
        android:id="@+id/list_checkable"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        tools:listitem="@layout/list_chackable_item">
    </ListView>

</LinearLayout>

list_chacakble_item:

<?xml version="1.0" encoding="utf-8"?>

    <CheckBox
        android:id="@+id/checkbox_number"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Abdallah"
        android:textStyle="bold"/>
<TextView
    android:id="@+id/text_number"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="7656156165156651"
    android:layout_marginLeft="30dp"/>

该对话框是从列表视图的适配器和适配器的代码进行分类:

      holder.replay.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            InstantTextBoxDialog exampleDialog=new InstantTextBoxDialog();

            exampleDialog.show(((Activity) activity).getFragmentManager(),"sadsdadsaadassd");
        }
    });

但是直到现在除了按钮和没有列表视图之外什么都没有显示

0 个答案:

没有答案
相关问题