我已经实现了你在图片中展示的东西。我使用的是自定义对话框,就像你想要使用的那样。我在xml文件中使用了Listview。
首先,初始化以下arraylist。
public static ArrayList<String> acceptpositionwhoesNearMe = new ArrayList<String>();
public static String AcceptCatagotyIDWhoesNearMe = "";
以下是我使用的
showDialog()代码。
public void showDialog() {
Log.i(TAG, "Inside Show Dialog");
final Dialog warning = new Dialog(logout_dialogue.this);
warning.requestWindowFeature(Window.FEATURE_NO_TITLE);
warning.setContentView(R.layout.YOUR_XML);
warning.setCancelable(false);
warning.getWindow().setGravity(Gravity.CENTER);
WindowManager mWinMgr;
mWinMgr = (WindowManager) this.getSystemService(Context.WINDOW_SERVICE);
int displayWidth = mWinMgr.getDefaultDisplay().getWidth();
warning.getWindow().setLayout(displayWidth - 75,
LayoutParams.WRAP_CONTENT);
warning.setOnDismissListener(new OnDismissListener() {
public void onDismiss(DialogInterface dialog) {
Log.i(TAG, "Inside Dialog interface");
warning.dismiss();
}
});
ListView listinterest = (ListView) warning
.findViewById(R.id.list_catagory);
CatagorySummaryAdapter adapter;
adapter = new CatagorySummaryAdapter(YOUR_ACTIVITY.this,
YOUR_ARRAYLIST_OF_CATAGORY, true);
listinterest.setAdapter(adapter);
Button btnOk = (Button) warning.findViewById(R.id.btn_close);
btnOk.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String Catagory = "";
int count = HomeActivity.acceptpositionwhoesNearMe.size();
if (count > 0) {
for (int i = 0; i < HomeActivity.acceptpositionwhoesNearMe
.size(); i++) {
int pos = Integer
.parseInt(HomeActivity.acceptpositionwhoesNearMe
.get(i));
if (Catagory.equals("")) {
Catagory = GetUserDetailsJsonParser.CategoryName
.get(pos);
HomeActivity.AcceptCatagotyIDWhoesNearMe = GetUserDetailsJsonParser.CategoryID
.get(pos);
} else {
Catagory = Catagory
+ ","
+ GetUserDetailsJsonParser.CategoryName
.get(pos);
HomeActivity.AcceptCatagotyIDWhoesNearMe = HomeActivity.AcceptCatagotyIDWhoesNearMe
+ ","
+ GetUserDetailsJsonParser.CategoryID
.get(pos);
}
}
Log.i(TAG, "Accept Catagory IDs WhoseNear Me"
+ HomeActivity.AcceptCatagotyIDWhoesNearMe);
GetUserDetailsJsonParser.InterestedIn = HomeActivity.AcceptCatagotyIDWhoesNearMe;
UpdateMap = true;
new GetUsersInRadiusAsyncTask().execute();
warning.dismiss();
} else {
Toast.makeText(WhosNearMe.this,
"Please Select One or More Catagory", 3).show();
}
}
});
warning.show();
}
这里是我的logout_dialogue.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/edittext_back_final"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<com.inukshk.CustomTextViewBold
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:text="Interested in"
android:textColor="#3C3C3C"
android:textSize="18sp"
android:textStyle="bold" />
</LinearLayout>
<ListView
android:id="@+id/list_catagory"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:cacheColorHint="#00000000"
android:divider="@android:color/transparent" >
</ListView>
<Button
android:id="@+id/btn_close"
android:layout_width="99dp"
android:layout_height="40dp"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dp"
android:background="@drawable/btn_back_final"
android:text="CLOSE"
android:textColor="#ffffff"
android:textSize="16dp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
这里是我的CatagorySummaryAdapter.java:
package com.inukshk.adapter;
import java.util.ArrayList;
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.BaseAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.inukshk.HomeActivity;
import com.inukshk.R;
import com.inukshk.CreateInukshk.BuildInukshk_3;
import com.inukshk.WhosNearMe.WhosNearMe;
public class CatagorySummaryAdapter extends BaseAdapter {
public Activity context;
String TAG = "CatagorySummaryAdapter";
public LayoutInflater inflater;
public ArrayList<String> Count;
boolean Dialogue;
public CatagorySummaryAdapter(Activity context, ArrayList<String> Count,
boolean Dialogue) {
super();
this.context = context;
this.inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
this.Count = Count;
this.Dialogue = Dialogue;
}
@Override
public int getCount() {
return Count.size();
}
@Override
public Object getItem(int position) {
return Count.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public int getItemViewType(int position) {
return position;
}
public class ViewHolder {
RelativeLayout lsummary_row;
TextView txtinterestname;
CheckBox chkinterest;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
int pos = position;
ViewHolder holder;
if (convertView == null) {
holder = new ViewHolder();
if (Dialogue) {
convertView = inflater.inflate(
R.layout.listview_summary_dialogue_row, null);
} else {
convertView = inflater.inflate(R.layout.listview_summary_row,
null);
}
holder.txtinterestname = (TextView) convertView
.findViewById(R.id.txtinterestname);
holder.lsummary_row = (RelativeLayout) convertView
.findViewById(R.id.lsummary_row);
holder.chkinterest = (CheckBox) convertView
.findViewById(R.id.chkinterest);
holder.chkinterest.setEnabled(true);
holder.chkinterest.setTag(position);
if (Dialogue) {
for (int i = 0; i < HomeActivity.acceptpositionwhoesNearMe.size(); i++) {
int index = Integer
.parseInt(HomeActivity.acceptpositionwhoesNearMe
.get(i));
if (index == position) {
holder.chkinterest.setChecked(true);
holder.chkinterest
.setButtonDrawable(R.drawable.checkbox_checked);
}
}
} else {
for (int i = 0; i < BuildInukshk_3.acceptposition.size(); i++) {
int index = Integer.parseInt(BuildInukshk_3.acceptposition
.get(i));
if (index == position) {
holder.chkinterest.setChecked(true);
holder.chkinterest
.setButtonDrawable(R.drawable.checkbox_checked);
}
}
}
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.chkinterest
.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
if (isChecked) {
buttonView
.setButtonDrawable(R.drawable.checkbox_checked);
int position = Integer.parseInt(buttonView.getTag()
.toString());
if (Dialogue) {
HomeActivity.acceptpositionwhoesNearMe.add(String
.valueOf(position));
Log.i(TAG, "Accept ID of Dialogue"
+ HomeActivity.acceptpositionwhoesNearMe);
} else {
BuildInukshk_3.acceptposition.add(String
.valueOf(position));
Log.i(TAG, "Accept ID"
+ BuildInukshk_3.acceptposition);
}
} else {
buttonView
.setButtonDrawable(R.drawable.checkbox_unchecked);
int position = Integer.parseInt(buttonView.getTag()
.toString());
if (Dialogue) {
if (HomeActivity.acceptpositionwhoesNearMe
.contains(String.valueOf(position))) {
HomeActivity.acceptpositionwhoesNearMe
.remove(String.valueOf(position));
Log.i(TAG,
"Accept ID Dialogue***"
+ HomeActivity.acceptpositionwhoesNearMe);
}
} else {
if (BuildInukshk_3.acceptposition
.contains(String.valueOf(position))) {
BuildInukshk_3.acceptposition.remove(String
.valueOf(position));
Log.i(TAG, "Accept ID ***"
+ BuildInukshk_3.acceptposition);
}
}
}
}
});
holder.txtinterestname.setText(Count.get(pos));
return convertView;
}
}
尝试阅读以下内容,可能会对您有所帮助。
Builder
类有一个setCustomTitle(View)
方法。 - userTextView
(实际标题)和all
CheckBox
。 - user