android的artdialog的用法

作了個小程序,最後沒有用上,但用法是徹底體現出來了:java

我定義了幾個按鈕的,代碼很清晰,沒有必要贅述了。android

protected void initFilterbar(){小程序

id_cat=(Button)findViewById(R.id.id_cat);ide

id_year=(Button)findViewById(R.id.id_year);ui

id_order=(Button)findViewById(R.id.id_order);this

id_cat.setOnClickListener(filter_click);get

id_year.setOnClickListener(filter_click);it

id_order.setOnClickListener(filter_click);io

}class

protected View.OnClickListener filter_click=new View.OnClickListener() {

@Override

public void onClick(View v) {

switch(v.getId())

{

case R.id.id_cat:{

showDialogPopup(R.id.id_cat);

break;

}

case R.id.id_year:{

showDialogPopup(R.id.id_year);

break;

}

case R.id.id_order:{

showDialogPopup(R.id.id_cat);

break;

}

}

}

};

protected void showDialogPopup(int viewId)

{

AlertDialog.Builder localBuilder = new AlertDialog.Builder(this);

switch(viewId)

{

case R.id.id_cat:{

//設置adpter

if(catadpter == null){

catadpter = new CatAdapter(this);

}

localBuilder.setAdapter(catadpter, new flPopupListener(catadpter)); 

break;

}

case R.id.id_year:{

break;

}

case R.id.id_order:{

break;

}

}

AlertDialog localAlertDialog = localBuilder.create();

localAlertDialog.show();

}

class flPopupListener implements DialogInterface.OnClickListener{

CatAdapter catadpter;

public flPopupListener(ListAdapter catadpter)

{

catadpter = (CatAdapter)catadpter;

}

@Override

public void onClick(DialogInterface dialog, int which) {

// TODO Auto-generated method stub

}

}

CatAdapter.java

package com.qvod.view;


 

import java.util.ArrayList;


 

import com.qvod.baidumovie.R;

import com.qvod.model.CatList;

import android.content.Context;

import android.view.LayoutInflater;

import android.view.View;

import android.view.ViewGroup;

import android.widget.BaseAdapter;

import android.widget.TextView;


 

public class CatAdapter extends BaseAdapter {

private LayoutInflater mInflater;

private ArrayList mData;

private Context context;  

public CatAdapter(Context context) {

this.context = context;  

this.mInflater = LayoutInflater.from(context);

mData = getData();

}

@Override

public int getCount() {

// TODO Auto-generated method stub

return mData.size();

}


 

@Override

public CatList getItem(int position) {

// TODO Auto-generated method stub

return mData.get(position);

}


 

@Override

public long getItemId(int position) {

// TODO Auto-generated method stub

return position;

}


 

@Override

public View getView(int position, View convertView, ViewGroup parent) {

final ViewHolder holder;

if(convertView == null){

convertView = mInflater.inflate(R.layout.dialog_list_item, null);

holder = new ViewHolder();

holder.vod_catid = (TextView) convertView.findViewById(R.id.catid);

holder.vod_catname = (TextView) convertView.findViewById(R.id.catname);

convertView.setTag(holder);

} else {

holder = (ViewHolder)convertView.getTag();

}

CatList locmap = (CatList)mData.get(position);

holder.vod_catid.setText(locmap.getCatid());

holder.vod_catname.setText(locmap.getCatname());

return convertView;

}

private ArrayList getData()

{

ArrayList data = new ArrayList();

ArrayList dsid=new ArrayList();

ArrayList dsname=new ArrayList();

ArrayList dyid=new ArrayList();

ArrayList dyname=new ArrayList();

dsid.add("1");

dsid.add("2");

dsid.add("3");

dsid.add("4");

dsid.add("5");

dsid.add("6");

dsname.add("內地");

dsname.add("韓劇");

dsname.add("港劇");

dsname.add("臺劇");

dsname.add("美劇");

dsname.add("日劇");

//電影的ID

dyid.add("1");

dyid.add("2");

dyid.add("3");

dyid.add("4");

dyid.add("5");

dyid.add("6");

dyid.add("7");

dyid.add("8");

dyname.add("動做");

dyname.add("劇情");

dyname.add("喜劇");

dyname.add("愛情");

dyname.add("恐怖");

dyname.add("科幻");

dyname.add("戰爭");

dyname.add("記錄");

for(int i=0;i

CatList ed=new CatList();

ed.setCatid(dsid.get(i));

ed.setCatname(dsname.get(i));

data.add(ed);

}

return data;

}

class ViewHolder{

TextView vod_catid;

TextView vod_catname;

}

}

相關文章
相關標籤/搜索