-1

私はウェブサイトからデータを取得しており、アンドロイドでリストビューとして表示していますが、データを使用すると、リストビューのデータも含むいくつかの html タグが表示されます。

Applicationadapter.java

public class ApplicationAdapter extends ArrayAdapter<Application>
{
    private List<Application> items;
    private LayoutInflater inflator;

    public ApplicationAdapter(Context context, List<Application> items)
    {
        super(context, R.layout.activity_row, items);
        this.items = items;
        inflator = LayoutInflater.from(getContext());
    }

    @Override
    public int getCount()
    {
        return items.size();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        ViewHolder holder = null;
        //View v = convertView;
        if ( convertView == null )
        {   
            convertView = inflator.inflate(R.layout.activity_row, null);
            LayoutInflater li = LayoutInflater.from(getContext());
            //convertView = inflator.inflate(R.layout.app_custom_list, null);
            holder = new ViewHolder();
            holder.text1 = (TextView) convertView.findViewById(R.id.text1);
            holder.chk = (CheckBox) convertView.findViewById(R.id.checkbox);
            /*holder.chk
            .setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

                /*@Override
                public void onCheckedChanged(CompoundButton view,
                        boolean isChecked) {
                    int getPosition = (Integer) view.getTag();
                    items.get(getPosition).setSelected(view.isChecked());

                }
            });*/
            convertView.setTag(holder);
            convertView.setTag(R.id.text1, holder.text1);
            convertView.setTag(R.id.checkbox, holder.chk);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }
        Application app = items.get(position);
        holder.chk.setTag(position);
        holder.text1.setText(items.get(position).getContent());
        //holder.chk.setChecked(items.get(position).isSelected());


        if ( app != null )
        {
            TextView titleText = (TextView) convertView.findViewById(R.id.titleTxt);
            if ( titleText != null )
                titleText.setText(Html.fromHtml(app.getContent()).toString());
                //titleText.setText(app.getContent());
               //holder.chk.setChecked(((View) Html.fromHtml(app.getContent())).isSelected());
        }
        return convertView;
    }
     static class ViewHolder {
        public TextView text1;
        public CheckBox chk;
    }
        //return convertView;


}

リストビューでhtmlタグを削除するために1行を使用しましたが、リストビューのようにhtmlタグが表示されていてもわかりません
。私の出力はリストビューでそのように表示されます hi <br>bye <br>'hello <br>.しかし、リストビューにそのhtmlタグを表示したくないので、どうすれば問題を解決できますか。

メインアクティビティ.java

public class MainActivity extends Activity implements FetchDataListener
{
    private static final int ACTIVITY_CREATE=0;
    private ProgressDialog dialog;
    ListView lv;
    //private ProjectsDbAdapter mDbHelper;
    //private SimpleCursorAdapter dataAdapter;


    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);


        setContentView(R.layout.activity_list_item);  
         //mDbHelper = new ProjectsDbAdapter(this);
            //mDbHelper.open();
            //fillData();
            //registerForContextMenu(getListView());

     lv =(ListView)findViewById(R.id.list);
        initView();
    }



    private void initView()
    {
        // show progress dialog
        dialog = ProgressDialog.show(this, "", "Loading...");
        String url = "http://dry-brushlands-3645.herokuapp.com/posts.json";
        FetchDataTask task = new FetchDataTask(this);
        task.execute(url);

        //mDbHelper.open();     
        //Cursor projectsCursor = mDbHelper.fetchAllProjects();
        //startManagingCursor(projectsCursor);

        // Create an array to specify the fields we want to display in the list (only TITLE)
        //String[] from = new String[]{ProjectsDbAdapter.KEY_TITLE};

        // and an array of the fields we want to bind those fields to (in this case just text1)
        //int[] to = new int[]{R.id.text1};

        /* Now create a simple cursor adapter and set it to display
        SimpleCursorAdapter projects = 
                new SimpleCursorAdapter(this, R.layout.activity_row, projectsCursor, from, to);
        setListAdapter(projects);
        */
        // create the adapter using the cursor pointing to the desired data 
        //as well as the layout information
         /*dataAdapter  = new SimpleCursorAdapter(
          this, R.layout.activity_row, 
          projectsCursor, 
          from, 
          to,
          0);
         setListAdapter(dataAdapter);
        */
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        //getMenuInflater().inflate(R.menu.activity_main, menu);
        super.onCreateOptionsMenu(menu);
         MenuInflater mi = getMenuInflater();
            mi.inflate(R.menu.activity_main, menu); 
        return true;

    }

     @Override
        public boolean onMenuItemSelected(int featureId, MenuItem item) {

                createProject();

            return super.onMenuItemSelected(featureId, item);
     }

     private void createProject() {
            Intent i = new Intent(this, ProjectEditActivity.class);
            startActivityForResult(i, ACTIVITY_CREATE);   
        }

     @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
            super.onActivityResult(requestCode, resultCode, intent);
            initView();
        }

    @Override
    public void onFetchComplete(List<Application> data)
    {
        // dismiss the progress dialog
        if ( dialog != null )
            dialog.dismiss();
        // create new adapter
        ApplicationAdapter adapter = new ApplicationAdapter(this, data);
        // set the adapter to list
        lv.setAdapter(adapter);
    }

    @Override
    public void onFetchFailure(String msg)
    {
        // dismiss the progress dialog
        if ( dialog != null )
            dialog.dismiss();
        // show failure message
        Toast.makeText(this, msg, Toast.LENGTH_LONG).show();
    }
}

リストビューのみのデータを表示したいのですが、htmltags は必要ありません。

if ( titleText != null ) then titleText.setText(Html.fromHtml(app.getContent()).toString());またはこのように書きたい場合、どの行が正しいか知りたいholder.text1.setText(Html.fromHtml(app.getContent()).toString());

4

1 に答える 1

1

あなたは変更によって行うことができます

holder.text1.setText(items.get(position).getContent());

holder.text1.setText(Html.fromHtml(items.get(position).getContent()));

于 2013-06-04T07:53:38.780 に答える