Android 微调器在自定义适配器Listview中递归调用MSelectedListener,而不选择任何项
我有两个微调器视图的自定义适配器列表视图 每个微调器都有一个后台进程。初始化时,将递归调用spinner view.OnItemSelectedListener,而不需要对侦听器进行任何外部输入 类文件Android 微调器在自定义适配器Listview中递归调用MSelectedListener,而不选择任何项,android,android-listview,android-asynctask,android-spinner,android-adapter,Android,Android Listview,Android Asynctask,Android Spinner,Android Adapter,我有两个微调器视图的自定义适配器列表视图 每个微调器都有一个后台进程。初始化时,将递归调用spinner view.OnItemSelectedListener,而不需要对侦听器进行任何外部输入 类文件 public class ClientListAdapter extends BaseAdapter implements SpinnerAdapter { Context context; int layoutResourceId; ArrayList<GetClientListDet
public class ClientListAdapter extends BaseAdapter implements SpinnerAdapter {
Context context;
int layoutResourceId;
ArrayList<GetClientListDetail> data = null;
ArrayList<GetClientListDetail> temp = null;
String ID, str;
Typeface typeface;
PopupWindow cp;
private ProgressDialog progressDialog;
String[] Status1 = new String[] { "Waiting", "Away","No Show"};
String[] Status2 = new String[] { "In Service",
"Generate Bill", "Completed" };
SpinnerAdapterlist TherapistAdapter = null;
ArrayAdapter<String> StatusAdapter = null;
ArrayList<GetTherapistProperties> TherapistList ;
private LayoutInflater inflater;
RemoveClient RC;
ChangeStatus CS;
ChangeTherapist CT;
ClientListHolder holder ;
int _therapistID;
GetClientListDetail ap;
GetTherapistProperties tp;
boolean networkavailable=false;
public ClientListAdapter(Context context, int textViewResourceId,
ArrayList<GetClientListDetail> gld, ArrayList<GetTherapistProperties> therapislist) {
super();
this.layoutResourceId = textViewResourceId;
this.context = context;
this.data = gld;
this.mGalleryCount1 = gld.size();
this.mGalleryCount2=gld.size();
this.TherapistList=therapislist;
inflater=LayoutInflater.from(context);
Resources res = context.getResources();
TherapistAdapter = new SpinnerAdapterlist(context,
R.layout.spinnerlayout, TherapistList);
StatusAdapter = new ArrayAdapter<String>(context,
android.R.layout.simple_dropdown_item_1line, Status1);
}
@Override
public int getCount() {
return data.size();
}
@Override
public GetClientListDetail getItem(int position) {
return data.get(position);
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View row = convertView;
if (row == null) {
holder = new ClientListHolder();
row = inflater.inflate(layoutResourceId, parent, false);
holder.tv_no = (TextView) row
.findViewById(R.id.tv_clientwaitlayout_no);
holder.tv_name = (TextView) row
.findViewById(R.id.tv_clientwaitlayout_name);
holder.tv_status = (Spinner) row
.findViewById(R.id.tv_clientwaitlayout_status);
holder.tv_therapist = (Spinner) row
.findViewById(R.id.tv_clientwaitlayout_therapist);
holder.iv_edit=(ImageView) row.findViewById(R.id.btn_clientwaitlayout_edit);
holder.iv_action = (ImageView) row
.findViewById(R.id.btn_clientwaitlayout_action);
holder.tv_unchange_therapist=(TextView) row.findViewById(R.id.tv_clientwaitlayout_unchange_name);
holder.tv_unchange_status=(TextView) row.findViewById(R.id.tv_clientwaitlayout_unchange_status);
row.setTag(holder);
} else {
holder = (ClientListHolder) row.getTag();
}
holder.tv_therapist.setAdapter(TherapistAdapter);
holder.tv_status.setAdapter(StatusAdapter);
ap = data.get(position);
tp=TherapistList.get(position);
holder.tv_name.setText(ap.getCLDName());
holder.tv_no.setText(ap.getCLDNo());
if(ap.getCLDStatus().equals("1") ){
Log.d("LOOP","Sub If condition");
holder.tv_therapist.setVisibility(View.VISIBLE);
holder.tv_status.setVisibility(View.VISIBLE);
holder.tv_unchange_therapist.setVisibility(View.GONE);
holder.tv_unchange_status.setVisibility(View.GONE);
holder.iv_action.setVisibility(View.GONE);
holder.iv_edit.setVisibility(View.VISIBLE);
try {
for(int x=0;x<TherapistList.size();x++){
if(ap.getCLDTherapist().equals(TherapistList.get(x).getID())){
holder.tv_therapist.setSelection(x);
}else{
}
}
} catch (NumberFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
holder.tv_status.setSelection(Integer.parseInt(ap.getCLDStatus()) - 1);
} catch (ArrayIndexOutOfBoundsException e2) {
// TODO Auto-generated catch block
holder.tv_status.setSelection(0);
}
}else if(ap.getCLDStatus().equals("2") | ap.getCLDStatus().equals("6")){
holder.tv_therapist.setVisibility(View.VISIBLE);
holder.tv_status.setVisibility(View.VISIBLE);
holder.tv_unchange_therapist.setVisibility(View.GONE);
holder.tv_unchange_status.setVisibility(View.GONE);
holder.iv_action.setVisibility(View.GONE);
holder.iv_edit.setVisibility(View.GONE);
try {
for(int x=0;x<TherapistList.size();x++){
if(ap.getCLDTherapist().equals(TherapistList.get(x).getID())){
holder.tv_therapist.setSelection(x);
}else{
}
}
} catch (NumberFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
if(ap.getCLDStatus().equals("2")){
holder.tv_status.setSelection(1);
}else{
holder.tv_status.setSelection(2);
}
} catch (ArrayIndexOutOfBoundsException e2) {
// TODO Auto-generated catch block
holder.tv_status.setSelection(0);
}
}else{
holder.tv_therapist.setVisibility(View.GONE);
holder.tv_status.setVisibility(View.GONE);
holder.tv_unchange_therapist.setVisibility(View.VISIBLE);
holder.tv_unchange_status.setVisibility(View.VISIBLE);
holder.iv_action.setVisibility(View.VISIBLE);
holder.iv_edit.setVisibility(View.GONE);
for(int y=0;y<TherapistList.size();y++){
if(ap.getCLDTherapist().equals(TherapistList.get(y).getID())){
holder.tv_unchange_therapist.setText(TherapistList.get(y).getName());
break;
}else{
holder.tv_unchange_therapist.setText("Not Available");
}
}
if (ap.getCLDStatus().equals("2")) {
holder.tv_unchange_status.setText(Status1[1]);
} else if (ap.getCLDStatus().equals("3")) {
holder.tv_unchange_status.setText(Status2[0]);
} else if (ap.getCLDStatus().equals("4")) {
holder.tv_unchange_status.setText(Status2[1]);
} else if (ap.getCLDStatus().equals("5")) {
holder.tv_unchange_status.setText(Status2[2]);
} else if (ap.getCLDStatus().equals("6")) {
holder.tv_unchange_status.setText(Status1[2]);
}
}
holder.tv_therapist.setTag(ap.getCLDClientID());
holder.tv_status.setTag(ap.getCLDClientID());
holder.iv_edit.setTag(ap.getCLDClientID());
holder.iv_action.setTag(ap.getCLDClientID());
holder.iv_action.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
try {
ImageView b = (ImageView) v;
String id = b.getTag().toString();
Log.d("ID is", id);
Intent CDV=new Intent(context, TabSample.class);
CDV.putExtra("ID", id);
//CDV.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
//context.startActivity(CDV);
((Activity) context).startActivityForResult(CDV,5);
try {
Log.d("POSITION", "" + position + " "
+ data.get(position).getCLDClientID());
} catch (ArrayIndexOutOfBoundsException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
holder.tv_status
.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
int id=arg2+1;
try {
try {
CS=new ChangeStatus();
CS.setClientID(data.get(position).getCLDClientID());
CS.setSalonID("1");
if(id==3){
CS.setStatus("6");
}else{
CS.setStatus(String.valueOf(id));
}
new LoadChangeStatus().execute();
} catch (ArrayIndexOutOfBoundsException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
holder.tv_therapist
.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
try {
try {
Spinner sp = (Spinner) arg0;
String str = sp.getTag().toString();
TextView th_id=(TextView)arg1.findViewById(R.id.spnradptno);
CT=new ChangeTherapist();
CT.setClientID(str);
CT.setSalonID("1");
CT.setTherapist(th_id.getText().toString());
new LoadChangeTherapist().execute();
Log.d("SPR TXT", th_id.getText().toString()+" "+position+" "+str);
} catch (ArrayIndexOutOfBoundsException e) {
// TODO Auto-generated catch block
Log.d("Error in spinner",e.toString());
}
} catch (Exception e) {
// TODO Auto-generated catch block
Log.d("Error2 in spinner",e.toString());
}
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
Log.d("Nothing","Selected");
}
});
holder.iv_edit.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
try {
ImageView b = (ImageView) v;
String id = b.getTag().toString();
Log.d("ID is", id);
Intent CDV=new Intent(context, TabSample.class);
CDV.putExtra("ID", id);
((Activity) context).startActivityForResult(CDV,5);
try {
Log.d("POSITION", "" + position + " "
+ data.get(position).getCLDClientID());
} catch (ArrayIndexOutOfBoundsException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
return row;
}
static class ClientListHolder {
TextView tv_no;
TextView tv_name;
Spinner tv_therapist;
Spinner tv_status;
ImageView iv_action;
ImageView iv_edit;
TextView tv_unchange_therapist;
TextView tv_unchange_status;
}
public class LoadChangeStatus extends AsyncTask<Integer, Integer, Integer> {
// Before running code in the separate thread
int LoadChangeStatus= 0;
@Override
protected void onPreExecute() {
// Create a new progress dialog
progressDialog = new ProgressDialog(context);
// Set the progress dialog to display a horizontal progress bar
// progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
// Set the dialog title to 'Loading...'
progressDialog.setTitle("Loading...");
// Set the dialog message to 'Loading application View, please
// wait...'
progressDialog.setMessage("Loading, please wait...");
// This dialog can't be canceled by pressing the back key
progressDialog.setCancelable(false);
// This dialog isn't indeterminate
progressDialog.setIndeterminate(false);
// The maximum number of items is 100
// Set the current progress to zero
// Display the progress dialog
progressDialog.show();
}
// The code to be executed in a background thread.
@Override
protected Integer doInBackground(Integer... params) {
try {
// temp.clear();
networkavailable=new Network().isNetworkAvailable(context);
if(networkavailable){
temp = CS.Change_Status(CS, context);
LoadChangeStatus=1;
}else{
LoadChangeStatus=2;
}
} catch (Exception e) {
// TODO Auto-generated catch block
Log.d("ERROR", "LoadChangeStatus backgroung");
}
return null;
}
// Update the progress
@Override
protected void onProgressUpdate(Integer... values) {
// set the current progress of the progress dialog
}
// after executing the code in the thread
@Override
protected void onPostExecute(Integer result) {
// close the progress dialog
progressDialog.dismiss();
if(LoadChangeStatus==1){
try {
data.clear();
data.addAll(temp);
notifyDataSetChanged();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}else if(LoadChangeStatus==2){
Toast.makeText(context, "Network Not Available", Toast.LENGTH_LONG).show();
}else{
Toast.makeText(context, "Changing Status Failed. Please Try Again", Toast.LENGTH_LONG).show();
}
}
}
public class LoadChangeTherapist extends
AsyncTask<Integer, Integer, Integer> {
// Before running code in the separate thread
int LoadChangeTherapist = 0;
@Override
protected void onPreExecute() {
// Create a new progress dialog
progressDialog = new ProgressDialog(context);
// Set the progress dialog to display a horizontal progress bar
// progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
// Set the dialog title to 'Loading...'
progressDialog.setTitle("Loading...");
// Set the dialog message to 'Loading application View, please
// wait...'
progressDialog.setMessage("Loading, please wait...");
// This dialog can't be canceled by pressing the back key
progressDialog.setCancelable(false);
// This dialog isn't indeterminate
progressDialog.setIndeterminate(false);
// The maximum number of items is 100
// Set the current progress to zero
// Display the progress dialog
progressDialog.show();
}
// The code to be executed in a background thread.
@Override
protected Integer doInBackground(Integer... params) {
try {
// temp.clear();
networkavailable=new Network().isNetworkAvailable(context);
if(networkavailable){
temp = CT.Get_Change_Therapist(CT, context);
LoadChangeTherapist=1;
}else{
LoadChangeTherapist=2;
}
} catch (Exception e) {
// TODO Auto-generated catch block
Log.d("ERROR", "LoadChangeStatus backgroung");
}
return null;
}
// Update the progress
@Override
protected void onProgressUpdate(Integer... values) {
// set the current progress of the progress dialog
}
// after executing the code in the thread
@Override
protected void onPostExecute(Integer result) {
// close the progress dialog
progressDialog.dismiss();
if (LoadChangeTherapist == 1) {
try {
data.clear();
data.addAll(temp);
notifyDataSetChanged();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else if (LoadChangeTherapist == 2) {
Toast.makeText(context, "Network Not Available", Toast.LENGTH_LONG).show();
}else{
Toast.makeText(context, "Removing Client Failed. Please Try Again", Toast.LENGTH_LONG).show();
}
}
}
public class LoadRemoveClient extends AsyncTask<Integer, Integer, Integer> {
// Before running code in the separate thread
int LoadRemoveClient = 0;
@Override
protected void onPreExecute() {
// Create a new progress dialog
progressDialog = new ProgressDialog(context);
// Set the progress dialog to display a horizontal progress bar
// progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
// Set the dialog title to 'Loading...'
progressDialog.setTitle("Loading...");
// Set the dialog message to 'Loading application View, please
// wait...'
progressDialog.setMessage("Loading, please wait...");
// This dialog can't be canceled by pressing the back key
progressDialog.setCancelable(false);
// This dialog isn't indeterminate
progressDialog.setIndeterminate(false);
// The maximum number of items is 100
// Set the current progress to zero
// Display the progress dialog
progressDialog.show();
}
// The code to be executed in a background thread.
@Override
protected Integer doInBackground(Integer... params) {
Log.d("ERROR", "LoadRemoveClient backgroung");
try {
networkavailable=new Network().isNetworkAvailable(context);
if(networkavailable){
temp = RC.Get_Client_List_Detail(RC, context);
LoadRemoveClient=1;
}else{
LoadRemoveClient=2;
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
// Update the progress
@Override
protected void onProgressUpdate(Integer... values) {
// set the current progress of the progress dialog
}
// after executing the code in the thread
@Override
protected void onPostExecute(Integer result) {
// close the progress dialog
progressDialog.dismiss();
if (LoadRemoveClient == 1) {
try {
data.clear();
data.addAll(temp);
notifyDataSetChanged();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else if (LoadRemoveClient == 2) {
Toast.makeText(context, "Network Not Available", Toast.LENGTH_LONG).show();
}else{
Toast.makeText(context, "Removing Client Failed. Please Try Again", Toast.LENGTH_LONG).show();
}
}
}
}
公共类ClientListAdapter扩展BaseAdapter实现SpinnerAdapter{
语境;
国际布局资源;
ArrayList数据=null;
ArrayList temp=null;
字符串ID,str;
字体;
波普温多cp;
私有进程对话;
字符串[]状态1=新字符串[]{“等待”、“离开”、“不显示”};
字符串[]状态2=新字符串[]{“正在使用”,
“生成票据”、“已完成”};
SpinnerAdapterlist TherapisAdapter=null;
ArrayAdapter StatusAdapter=null;
ArrayList治疗师;
私人充气机;
RemoveClient RC;
改变状态;
改变CT;
客户名单持有人;
国际治疗师;
GetClientListDetailAP;
gettp;
布尔网络可用=假;
公共ClientListAdapter(上下文,int textViewResourceId,
ArrayList gld,ArrayList治疗师){
超级();
this.layoutResourceId=textViewResourceId;
this.context=上下文;
这个数据=gld;
this.mGalleryCount1=gld.size();
this.mGalleryCount2=gld.size();
这个。治疗师=治疗师;
充气器=充气器。从(上下文);
Resources res=context.getResources();
TherapisAdapter=新的SpinnerAdapterlist(上下文,
R.布局、喷丝头布局、治疗师);
StatusAdapter=新阵列适配器(上下文,
android.R.layout.simple\u下拉菜单\u项目\u 1行,状态1);
}
@凌驾
public int getCount(){
返回data.size();
}
@凌驾
公共GetClientListDetail getItem(int位置){
返回数据。获取(位置);
}
@凌驾
公共长getItemId(int位置){
返回0;
}
@凌驾
公共视图getView(最终整数位置、视图转换视图、视图组父视图){
视图行=转换视图;
if(行==null){
holder=新的ClientListHolder();
行=充气机。充气(layoutResourceId,父级,false);
holder.tv_no=(TextView)行
.findviewbyd(R.id.tv_clientwaitlayout_no);
holder.tv_name=(TextView)行
.findviewbyd(R.id.tv_clientwaitlayout_name);
holder.tv_状态=(微调器)行
.findviewbyd(R.id.tv_clientwaitlayout_状态);
holder.tv_=(微调器)行
.findviewbyd(R.id.tv_clientwaitlayou_治疗师);
holder.iv_edit=(ImageView)row.findViewById(R.id.btn_clientwaitlayout_edit);
holder.iv_操作=(图像视图)行
.findviewbyd(R.id.btn_clientwaitlayou_action);
holder.tv_unchange_治疗师=(TextView)row.findViewById(R.id.tv_clientwaitlayout_unchange_name);
holder.tv_unchange_status=(TextView)row.findViewById(R.id.tv_clientwaitlayout_unchange_status);
row.setTag(支架);
}否则{
holder=(ClientListHolder)行。getTag();
}
持有者。电视治疗师。设置适配器(治疗师适配器);
holder.tv_status.setAdapter(状态适配器);
ap=数据获取(位置);
tp=治疗师获取(位置);
holder.tv_name.setText(ap.getCLDName());
holder.tv_no.setText(ap.getCLDNo());
如果(ap.getCLDStatus()等于(“1”)){
Log.d(“循环”、“子If条件”);
holder.tv_.setVisibility(View.VISIBLE);
支架。电视状态。设置可见性(视图。可见);
holder.tv\u unchange\u治疗师.setVisibility(View.GONE);
holder.tv\u unchange\u status.setVisibility(View.GONE);
支架。iv_动作。设置可见性(视图。消失);
holder.iv_编辑设置可见性(View.VISIBLE);
试一试{
对于(int x=0;x arg0){
//TODO自动生成的方法存根
Log.d(“无”、“选定”);
}
});
holder.iv_edit.setOnClickListener(新的OnClickListener(){
@凌驾
公共void onClick(视图v){
//TODO自动生成的方法存根
试试{
ImageView b=(ImageView)v;
字符串id=b.getTag().toString();
Log.d(“ID是”,ID);
Intent CDV=新的Intent(上下文,TabSample.class);
CDV.putExtra(“ID”,ID);
((活动)背景)。startActivityForResult(CDV,5);
试一试{
Log.d(“位置”,“位置+”
+data.get(position.getCLDClientID());
}捕获(阵列索引边界外异常e){
//TODO自动生成的捕捉块
e、 printStackTrace();
}
}捕获(例外e){
//TODO自动生成的捕捉块
e、 printStackTrace();
}
}
});
返回行;
}
静态类ClientListHolder{
TextView电视频道;
TextView tv_名称;
斯宾纳电视治疗师;
微调器tv_状态;
ImageView iv_行动;
图像视图iv_编辑;
TextView tv_unchange_治疗师;
TextView tv_未更改_状态;
}
公共类LoadChangeStatus扩展异步任务{
//在单独的线程中运行代码之前
int LoadChangeStatus=0;
@凌驾
受保护的void onPreExecute(){
//创建一个新的进度对话框
progressDialog=新建progressDialog(上下文);
//将“进度”对话框设置为显示水平进度条
//progressDialog.setProgressStyle(progressDialog.STYLE_水平);
progressDialog.setProgressStyle(progressDialog.STYLE_微调器);
//将对话框标题设置为“正在加载…”
progressDialog.setTitle(“加载…”);
//请将对话框消息设置为“正在加载应用程序视图”
//等等……”
setMessage(“正在加载,请稍候…”);
//按后退键无法取消此对话框
进步
if (row == null) {
holder = new ClientListHolder();
row = inflater.inflate(layoutResourceId, parent, false);
holder.tv_no = (TextView) row
.findViewById(R.id.tv_clientwaitlayout_no);
holder.tv_name = (TextView) row
.findViewById(R.id.tv_clientwaitlayout_name);
holder.tv_status = (Spinner) row
.findViewById(R.id.tv_clientwaitlayout_status);
holder.tv_therapist = (Spinner) row
.findViewById(R.id.tv_clientwaitlayout_therapist);
holder.iv_edit=(ImageView) row.findViewById(R.id.btn_clientwaitlayout_edit);
holder.iv_action = (ImageView) row
.findViewById(R.id.btn_clientwaitlayout_action);
holder.tv_unchange_therapist=(TextView) row.findViewById(R.id.tv_clientwaitlayout_unchange_name);
holder.tv_unchange_status=(TextView) row.findViewById(R.id.tv_clientwaitlayout_unchange_status);
holder.tv_therapist.setAdapter(TherapistAdapter);
holder.tv_status.setAdapter(StatusAdapter);
row.setTag(holder);
} else {
holder = (ClientListHolder) row.getTag();
}