首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >微调控件显示应用包名称+地址

微调控件显示应用包名称+地址
EN

Stack Overflow用户
提问于 2018-04-24 03:45:14
回答 1查看 182关注 0票数 0

我通过扩展ArrayAdapter<>类创建了一个自定义微调器:

代码语言:javascript
复制
public class SpinnerAdapter extends ArrayAdapter<Category> {
    Activity activity ;
    List<Category> mCategoriesList ;
    int itemResourceId ;

    public SpinnerAdapter(Activity activity , List<Category> CategoriesList,int itemResourceId){

        super(activity,itemResourceId,CategoriesList);
        this.activity=activity;
        this.mCategoriesList=CategoriesList;
        this.itemResourceId=itemResourceId;

    }

    public View getView(int position , View convertView , ViewGroup parent){
        View MyCustomLayout = convertView ;
        if(MyCustomLayout== null){
            LayoutInflater Inflator = activity.getLayoutInflater();
            MyCustomLayout = Inflator.inflate(R.layout.custom_spinner_layout,parent,false);

        }
        TextView FullN = MyCustomLayout.findViewById(R.id.CatSubCatName);
        ImageView ProfP = MyCustomLayout.findViewById(R.id.BloodyIcon);
        FullN.setText(mCategoriesList.get(position).getName());



        return MyCustomLayout ;
    }
}

提供的mCategoriesList是通过解析jsonArray获得的:

代码语言:javascript
复制
try {
    JSONArray liste = new JSONArray(response);
    for (int i=0;i<liste.length();i++){
        JSONObject obj = liste.getJSONObject(i);
        Category cat= new Category();
        cat.setName(obj.getString("name"));
        cat.setID(obj.getInt("ID_categorie"));
        mCategoriesList.add(cat);}}
        catch(Throwable t){
        t.printStackTrace();
    }

下面是与微调器对应的自定义布局的XML代码:

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">
    <ImageView
        android:id="@+id/BloodyIcon"
        android:layout_marginStart="20dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/CatSubCatName"
        android:textSize="21sp"
        android:textColor="@color/Purple"
        android:fontFamily="sans-serif-condensed"
        android:layout_marginStart="20dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</LinearLayout>

这是Category类:

代码语言:javascript
复制
public class Category {
    private int ID ;
    private  String Name ;

    public Category(int ID ,String Name){
        this.ID=ID ;
        this.Name=Name ;
    }
    public Category(){

    }

    public int getID() {
        return ID;
    }

    public void setID(int ID) {
        this.ID = ID;
    }

    public String getName() {
        return Name;
    }

    public void setName(String name) {
        Name = name;
    }
}

问题是,当我单击微调器时,我得到的不是类别名称的列表,而是类似于:packagename.Category@(随机字符),然而所选项目正确地显示了名称,我是否遗漏了什么?

Spinner Output

EN

回答 1

Stack Overflow用户

发布于 2018-04-24 04:19:25

通过在适当的位置放置断点来确保正确解析名称

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49988849

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档