Android 如何为同一类中的两个布局充气?
我有一个Android 如何为同一类中的两个布局充气?,android,layout-inflater,popupwindow,Android,Layout Inflater,Popupwindow,我有一个列表视图,当我在视图中单击它时,我想在弹出窗口中显示所选列表内容。我该怎么做 这是我的密码: public class EventbyDate extends ListActivity { Context cont; private Runnable DateEventListThread; public String DateEventListThreadResponse; private ProgressDialog m_ProgDialog = nu
列表视图
,当我在视图中单击它时,我想在弹出窗口中显示所选列表内容。我该怎么做
这是我的密码:
public class EventbyDate extends ListActivity {
Context cont;
private Runnable DateEventListThread;
public String DateEventListThreadResponse;
private ProgressDialog m_ProgDialog = null;
public DateEventListAdapter DateEventList_adapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.eventsbydate);
GetDateEventList();
this.DateEventList_adapter = new DateEventListAdapter(this,R.layout.eventsbydate_list,
RoamMeo_Config.DateEventList);
setListAdapter(this.DateEventList_adapter);
}
@Override
public void onPause() {
super.onPause();
this.finish();
}
void GetDateEventList() {
m_ProgDialog = ProgressDialog.show(EventbyDate.this, " Please wait",
"Collecting Data..", true);
DateEventListThread = new Runnable() {
@Override
public void run() {
DateEventListThread = null;
try {
} catch (Exception e) {
e.printStackTrace();
}
runOnUiThread(returnResponse);
}
};
Thread thread = new Thread(null, DateEventListThread, "DateEventListThread");
thread.start();
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
LayoutInflater inflater = (LayoutInflater) EventbyDate.
this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
PopupWindow pw = new PopupWindow(inflater.inflate(R.layout.popup,null,
false),300,400,true);
pw.showAtLocation(findViewById(R.id.txt_start_date),
Gravity.CENTER, 0,0);
}
private Runnable returnResponse = new Runnable() {
@Override
public void run() {
try {
if (DateEventListThreadResponse != null&&
DateEventListThreadResponse.length() > 0) {
boolean check =
XMLParsing.EventDate_List_Response(DateEventListThreadResponse);
if(check) {
DateEventList_adapter.notifyDataSetChanged();
} else {
Toast msg =
Toast.makeText(EventbyDate.this,"No list... ",Toast.LENGTH_LONG);
msg.setGravity(Gravity.CENTER,
msg.getXOffset() / 2,msg.getYOffset() / 2);
msg.show();
}
}
if (m_ProgDialog != null)
m_ProgDialog.dismiss();
m_ProgDialog = null;
} catch (Exception e) {
if (m_ProgDialog != null)
m_ProgDialog.dismiss();
m_ProgDialog = null;
}
}
};
class DateEventListAdapter extends ArrayAdapter<SaveDateEventList> {
ArrayList<SaveDateEventList> items;
public DateEventListAdapter(Context context, int
textViewResourceId,
ArrayList<SaveDateEventList> items) {
super(context, textViewResourceId, items);
this.items = items;
}
@Override
public View getView(int position, View convertView, ViewGroup
parent) {
View v = convertView;
final SaveDateEventList d = items.get(position);
if (v == null) {
LayoutInflater vi = (LayoutInflater)
getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.eventsbydate_list, null);
}
if (!items.isEmpty()) {
if (d != null) {
TextView start_date = (TextView)
v.findViewById(R.id.txt_start_date);
start_date.setText(d.ev_start_date);
TextView start_time = (TextView)
v.findViewById(R.id.txt_start_time);
start_time.setText(d.ev_start_time);
TextView poptext = (TextView)
v.findViewById(R.id.poptext);
poptext.setText(d.ev_start_time);
}
}
return v;
}
}
}
public类EventbyDate扩展了ListActivity{
语境控制;
私有可运行DateEventListThread;
公共字符串DateEventListThreadResponse;
private ProgressDialog m_ProgDialog=null;
公共DateEventListAdapter DateEventList_适配器;
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.eventsbydate);
GetDateEventList();
this.DateEventList_adapter=新的dateeventlistapter(this,R.layout.eventsbydate_list,
RoamMeo_Config.DateEventList);
setListAdapter(此.DateEventList_适配器);
}
@凌驾
公共无效暂停(){
super.onPause();
这个;
}
void GetDateEventList(){
m_ProgDialog=ProgressDialog.show(EventbyDate.this,“请稍候”,
“收集数据…”,正确);
DateEventListThread=new Runnable(){
@凌驾
公开募捐{
DateEventListThread=null;
试一试{
}捕获(例外e){
e、 printStackTrace();
}
runOnUiThread(返回响应);
}
};
线程线程=新线程(null,DateEventListThread,“DateEventListThread”);
thread.start();
}
@凌驾
受保护的void onListItemClick(列表视图l、视图v、整数位置、长id){
super.onListItemClick(左、右、位置、id);
LayoutFlater充气器=(LayoutFlater)EventbyDate。
这个.getSystemService(Context.LAYOUT\u充气机\u服务);
PopupWindow pw=新的PopupWindow(充气机充气(R.layout.popup,null,
假),300400,真);
pw.showAtLocation(findViewById(R.id.txt\u开始日期),
重心,0,0);
}
private Runnable returnResponse=new Runnable(){
@凌驾
public void run(){
试一试{
如果(DateEventListThreadResponse!=null&&
DateEventListThreadResponse.length()>0){
布尔检查=
EventDate_列表_响应(DateEventListThreadResponse);
如果(检查){
DateEventList_适配器.notifyDataSetChanged();
}否则{
吐司味精=
Toast.makeText(EventbyDate.this,“无列表…”,Toast.LENGTH\u LONG);
msg.setGravity(重心,
msg.getXOffset()/2,msg.getYOffset()/2);
msg.show();
}
}
如果(m_ProgDialog!=null)
m_ProgDialog.discouse();
m_ProgDialog=null;
}捕获(例外e){
如果(m_ProgDialog!=null)
m_ProgDialog.discouse();
m_ProgDialog=null;
}
}
};
类DateEventListAdapter扩展了ArrayAdapter{
数组列表项;
公共DateEventListAdapter(上下文,int
textViewResourceId,
ArrayList项目){
super(上下文、textViewResourceId、项);
这个项目=项目;
}
@凌驾
公共视图getView(int位置、视图转换视图、视图组
(家长){
视图v=转换视图;
final SaveDateEventList d=items.get(位置);
如果(v==null){
LayoutInflater vi=(LayoutInflater)
getSystemService(上下文布局\充气机\服务);
v=vi.充气(R.layout.eventsbydate_列表,空);
}
如果(!items.isEmpty()){
如果(d!=null){
TextView开始日期=(TextView)
v、 findViewById(R.id.txt\u开始日期);
开始日期.setText(d.ev\u开始日期);
TextView开始时间=(TextView)
v、 findViewById(R.id.txt\u开始时间);
start_time.setText(d.ev_start_time);
TextView poptext=(TextView)
v、 findViewById(R.id.poptext);
setText(d.ev_开始时间);
}
}
返回v;
}
}
}
您可以这样做,受保护的void onListItemClick(ListView l,View v,int position,long id){YourObject o=l.getItemAtPosition(position);}
。之后,您必须通过该获取的对象设置您需要在弹出屏幕中显示的内容 但弹出屏幕本身显示在该列表项上单击。如何在弹出窗口中设置数据?那是我的qn<代码>@Override protected void onListItemClick(ListView l,View v,int position,long id){super.onListItemClick(l,v,position,id);LayoutFlater充气器=(LayoutFlater)EventbyDate.this.getSystemService(Context.LAYOUT\u充气器\u SERVICE);PopupUpWindow pw=新的PopupUpWindow(充气器.inflate(R.LAYOUT.popup,null,false),300400,true);pw.showAtLocation(findviewbyd(R.id.txt_start_date),Gravity.CENTER,0,0);}