Esr*_*raa 8 android listview popup
我正在创建一个应用程序并使用ListView的自定义适配器.它正在活动中工作
public class Adapter extends ArrayAdapter {
Context mContext;
int resourceID;
ArrayList<String> names;
public Adapter(Context context, int resource, ArrayList<String> objects) {
super(context, resource, objects);
this.mContext = context;
this.resourceID=resource;
this.names= objects;
}
@Override
public String getItem(int position) {
return names.get(position);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
LayoutInflater inflater = LayoutInflater.from(mContext);
row = inflater.inflate(resourceID, parent, false);
TextView text = (TextView) row.findViewById(R.id.text);
text.setText(names.get(position));
return row;
}
}
Run Code Online (Sandbox Code Playgroud)
我使用此代码使它们出现在活动上
myNames= (ListView) findViewById(R.id.List);
adapter = new Adapter(this,R.layout.names_view, Current.Names);
myNames.setAdapter(adapter);
Run Code Online (Sandbox Code Playgroud)
现在我想点击一个按钮,使弹出窗口显示相同的列表,任何帮助?
tah*_*pam 13
您可以这样做:
1)在按钮单击上创建自定义对话框:
Button clickButton = (Button) findViewById(R.id.clickButton);
clickButton.setOnClickListener( new OnClickListener() {
@Override
public void onClick(View v) {
final Dialog dialog = new Dialog(YourActivity.this);
dialog.setContentView(R.layout.custom_dialog);
dialog.setTitle("Title...");
myNames= (ListView) dialog.findViewById(R.id.List);
adapter = new Adapter(YourActivity.this,R.layout.names_view, Current.Names);
myNames.setAdapter(adapter);
dialog.show();
}
});
Run Code Online (Sandbox Code Playgroud)
2)在对话框布局中添加listview(custom_dialog.xml):
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView
android:id="@+id/List"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16084 次 |
| 最近记录: |