栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何在TextView中获取微调器值

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何在TextView中获取微调器值

定义自定义界面,该界面从多个项目选择对话框中进行回调。

public interface MultipleItemSelectListener {    public void onSelected(String value,String ids);}

自定义多项选择对话框方法。

参量

内容 :您的活动内容参考。

title :对话框标题。

jsonArrayString :您的jsonarray响应作为字符串。

MultipleItemSelectListener :对选定项的侦听 器进行 自定义。

public void getMultiSelectionDialog(final Context context,final String title, String jsonString, final String value, final MultipleItemSelectListener target) {    final ArrayList<String> values = new ArrayList<String>();    final ArrayList<String> ids = new ArrayList<String>();    final String BUSINESS_ID="id";    final String BUSINESS_NAME="name";    try {        JSonArray jsonArray = new JSonArray(jsonString);        int size = jsonArray.length();        for (int i = 0; i < size; i++) { values.add(((JSONObject) jsonArray.get(i)).getString(BUSINESS_NAME).trim()); ids.add(((JSONObject) jsonArray.get(i)).getString(BUSINESS_ID).trim());        }    } catch (JSonException e) {        e.printStackTrace();    }    final boolean[] selections = new boolean[values.size()];    final StringBuilder newValue = new StringBuilder();    final StringBuilder newIds = new StringBuilder();    alertDialog alert = null;    if (value.length() > 0) {        String[] oldValue = value.split(",");        int size = values.size();        for (int i = 0; i < size; i++) { int len = oldValue.length; for (int j = 0; j < len; j++) {     if (values.get(i).trim().equalsIgnoreCase(oldValue[j].trim())) {         selections[i] = true;         break;     } }        }    }    alertDialog.Builder builder = new alertDialog.Builder(context);    builder.setTitle(title);    builder.setMultiChoiceItems(values.toArray(new CharSequence[values.size()]), selections, new DialogInterface.onMultiChoiceClickListener() {        @Override        public void onClick(DialogInterface dialog, int which, boolean isChecked) { selections[which] = isChecked;        }    });    builder.setPositiveButton("Done", new DialogInterface.onClickListener() {        @Override        public void onClick(DialogInterface dialog, int which) { int size = selections.length; for (int i = 0; i < size; i++) {     if (selections[i]) {         newValue.append(newValue.length() > 0 ? "," + values.get(i) : values.get(i));         newIds.append(newIds.length() > 0 ? "," + ids.get(i) : ids.get(i));     } } target.onSelected(newValue.toString(),newIds.toString());        }    });    builder.setNegativeButton("Cancel", new DialogInterface.onClickListener() {        @Override        public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); int size = selections.length; for (int i = 0; i < size; i++) {     if (selections[i]) {         newIds.append(newIds.length() > 0 ? "," + ids.get(i) : ids.get(i));     } } target.onSelected(value,newIds.toString());        }    });    alert = builder.create();    alert.show();}

如何获取MultiSelectionDialog:

class LoadBusiness extends AsyncTask<Void,Void,String> {    Context context;    public LoadBusiness(Context context){        this.context=context;    }    private ProgressDialog pDialog;    @Override    protected void onPreExecute() {        super.onPreExecute();        pDialog = new ProgressDialog(context);        pDialog.setMessage("Loading...");        pDialog.setIndeterminate(false);        pDialog.setCancelable(true);        pDialog.show();    }    @Override    protected String doInBackground(Void... params) {        ServiceHandler sh = new ServiceHandler();        String jsonStr = sh.makeServiceCall(BUSINESS_URL, ServiceHandler.GET);        Log.d("Response: ", "> " + jsonStr);        return jsonStr;    }    protected void onPostExecute(String result) {        super.onPostExecute(result);        pDialog.dismiss();        setTextViewWithMultipleSelectionDialog(context,result);    }}  public void setTextViewWithMultipleSelectionDialog(final Context context,final String jsonArrayString){    splang.setonClickListener(new View.onClickListener() {        @Override        public void onClick(View v) { getMultiSelectionDialog(context,"Countries",jsonArrayString,splang.getText().toString(),new MultipleItemSelectListener() {     @Override     public void onSelected(String value) {         splang.setText(value);     } });        }    }); } @Override protected void onCreate(Bundle savedInstanceState) {   super.onCreate(savedInstanceState);   setContentView(R.layout.activity_main);   splang=(TextView)findViewById(R.id.txtvw);   new LoadBusiness(this).execute();}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/616742.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号