Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/206.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 更改自定义listview中的特定项文本_Android_Custom Lists - Fatal编程技术网

Android 更改自定义listview中的特定项文本

Android 更改自定义listview中的特定项文本,android,custom-lists,Android,Custom Lists,我有一个自定义列表视图,它有三个视图,两个文本视图和一个列表视图。我想在特定位置更改其中一个文本视图,我想将其中一个项目文本视图设置为所有者,但正确的项目文本视图和最后一个项目文本视图设置为所有者。 这是我的代码: 谢谢 我得到了答案,如果我的代码是: @Override public View getView(int position, View convertView, ViewGroup parent) { db.open(); View row=c

我有一个自定义列表视图,它有三个视图,两个文本视图和一个列表视图。我想在特定位置更改其中一个文本视图,我想将其中一个项目文本视图设置为所有者,但正确的项目文本视图和最后一个项目文本视图设置为所有者。 这是我的代码: 谢谢


我得到了答案,如果我的代码是:

@Override
    public View getView(int position, View convertView, ViewGroup parent) {
        db.open();
        View row=convertView;
        if(row==null){
        LayoutInflater inflater=(LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        row=inflater.inflate(R.layout.custom_list_main, parent, false);
        }
        //final String o=objects.get(position);
        //if(o!=null){
            TextView name=(TextView) row.findViewById(R.id.name);
            String nameString=mAdapter.getItem(position);
            name.setText(nameString);
            // ImageView photo= (ImageView) row.findViewById(R.id.photo);
            TextView ownerSign=(TextView) row.findViewById(R.id.owner_text);
            //String value =getItem(position);

            if(checkOwner()!=null && getItem(position).equals(checkOwner())){
                    ownerSign.setText(getResources().getString(R.string.owner));
            }
            else{
                ownerSign.setText(getResources().getString(R.string.nothing));
            }

        //}

        db.close();
        return row;

    }


    public String checkOwner(){
        Cursor c=db.getAllPerson();
        if(c.moveToFirst()){
            do{

                if(c.getInt(c.getColumnIndex(Constants.OWNER))>0){
                    return c.getString(c.getColumnIndex(Constants.PERSON_NAME));
                }
            }while(c.moveToNext());     
        }
        return null;
    }
@SuppressLint(“SimpleDataFormat”)
公共视图getView(int位置、视图转换视图、视图组父视图){
视图vi=转换视图;
if(convertView==null)
vi=充气机。充气(R.layout.gustomgrid,null);
Typeface tf=Typeface.createFromAsset(activity.getAssets(),
“字体/数字-7.ttf”);
TextView名称=(TextView)vi.findViewById(R.id.date);
TextView freq=(TextView)vi.findviewbyd(R.id.freq);
名称.设置字体(tf);
HashMap details=新的HashMap();
详细信息=data.get(位置);
name.setText(details.get(“freq”));
Logger.infoMessage(“位置”+位置);
如果(此.selectedPosition!=-1){
如果(位置==2){
name.setTextColor(Color.parseColor(#7FFF00”);
}
}
freq.setText(Html.fromHtml(“+details.get”(“mhz”)
+ ""));
返回vi;
}
它改变了listview中第二个位置的文本颜色。在此基础上,我们改变了任何位置的文本颜色或行颜色。
@Override
    public View getView(int position, View convertView, ViewGroup parent) {
        db.open();
        View row=convertView;
        if(row==null){
        LayoutInflater inflater=(LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        row=inflater.inflate(R.layout.custom_list_main, parent, false);
        }
        //final String o=objects.get(position);
        //if(o!=null){
            TextView name=(TextView) row.findViewById(R.id.name);
            String nameString=mAdapter.getItem(position);
            name.setText(nameString);
            // ImageView photo= (ImageView) row.findViewById(R.id.photo);
            TextView ownerSign=(TextView) row.findViewById(R.id.owner_text);
            //String value =getItem(position);

            if(checkOwner()!=null && getItem(position).equals(checkOwner())){
                    ownerSign.setText(getResources().getString(R.string.owner));
            }
            else{
                ownerSign.setText(getResources().getString(R.string.nothing));
            }

        //}

        db.close();
        return row;

    }


    public String checkOwner(){
        Cursor c=db.getAllPerson();
        if(c.moveToFirst()){
            do{

                if(c.getInt(c.getColumnIndex(Constants.OWNER))>0){
                    return c.getString(c.getColumnIndex(Constants.PERSON_NAME));
                }
            }while(c.moveToNext());     
        }
        return null;
    }
@SuppressLint("SimpleDateFormat")
    public View getView(int position, View convertView, ViewGroup parent) {
        View vi = convertView;

        if (convertView == null)
            vi = inflater.inflate(R.layout.coustomgrid, null);
        Typeface tf = Typeface.createFromAsset(activity.getAssets(),
                "fonts/digital-7.ttf");
        TextView name = (TextView) vi.findViewById(R.id.date);
        TextView freq = (TextView) vi.findViewById(R.id.freq);
        name.setTypeface(tf);

        HashMap<String, String> details = new HashMap<String, String>();
        details = data.get(position);
        name.setText(details.get("freq"));
        Logger.infoMessage("Position"+position);
        if(this.selectedPosition!=-1){
        if (position == 2){

            name.setTextColor(Color.parseColor("#7FFF00"));

        }
        }

        freq.setText(Html.fromHtml("<font color=#32cadb>" + details.get("mhz")
                + "</font>"));

        return vi;
    }

It change the text color on second position in listview.Based on that we change the textcolor or row color at any position.