Java listview中的android linkify

Java listview中的android linkify,java,android,Java,Android,我有以下代码: import java.util.ArrayList; import java.util.HashMap; import java.util.List; import org.apache.http.NameValuePair; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import com.romantic.aacplay.R; import and

我有以下代码:

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.apache.http.NameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import com.romantic.aacplay.R;
import android.app.ListActivity;
import android.app.ProgressDialog;
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.os.AsyncTask;
import android.os.Bundle;
// import android.text.Html;
// import android.text.Html;
import android.text.Html;
import android.util.Log;
import android.view.View;
import android.widget.ListAdapter;
import android.widget.SimpleAdapter;


public class PodCast extends ListActivity {
        private ProgressDialog pDialog;


        JSONParser jParser = new JSONParser();

        ArrayList<HashMap<String, String>> productsList;

        private static String url_all_products = "http://mysite.net/andro/pcast.php";
        private static final String TAG_SUCCESS = "success";
        private static final String TAG_PRODUCTS = "podcast";
        private static final String TAG_LINK = "link";
        private static final String TAG_NAME = "nume";

        JSONArray products = null;

        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.poadcast);

             GradientDrawable gd = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, new int[] {Color.RED,Color.BLACK});
                View title = getWindow().findViewById(android.R.id.title);
                View titleBar = (View) title.getParent();
                titleBar.setBackgroundDrawable(gd);


            productsList = new ArrayList<HashMap<String, String>>();

            new LoadAllProducts().execute();

        }

        class LoadAllProducts extends AsyncTask<String, String, String> {
            @Override
            protected void onPreExecute() {
                super.onPreExecute();
                pDialog = new ProgressDialog(PodCast.this);
                pDialog.setMessage("Se incarca. Asteapta...");
                pDialog.setIndeterminate(false);
                pDialog.setCancelable(false);
                pDialog.show();

            }

            protected String doInBackground(String... args) {

                List<NameValuePair> params = new ArrayList<NameValuePair>();
                JSONObject json = jParser.makeHttpRequest(url_all_products, "GET", params);


                Log.d("Ultimele 10 piese: ", json.toString());

                try {
                    int success = json.getInt(TAG_SUCCESS);

                    if (success == 1) {
                        products = json.getJSONArray(TAG_PRODUCTS);
                        for (int i = 0; i < products.length(); i++) {
                            JSONObject c = products.getJSONObject(i);
                            String link = c.getString(TAG_LINK);
                            String name = c.getString(TAG_NAME);
                            HashMap<String, String> map = new HashMap<String, String>();
                            // String href = String.format("<a href=\"%s\"> %s </a>", link, name);
                            // String cici = Html.fromHtml(href).toString();
                            map.put(TAG_NAME, name);
                            map.put(TAG_LINK, "" + Html.fromHtml(link));
                            // map.put(TAG_LINK, link);
                            productsList.add(map);
                        }
                    } else {

                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }

                return null;
            }

            protected void onPostExecute(String file_url) {

                pDialog.dismiss();
                runOnUiThread(new Runnable() {
                    public void run() {
                        ListAdapter adapter = new SimpleAdapter(
                                PodCast.this, productsList,
                                R.layout.list_item, new String[] {
                                        TAG_NAME, TAG_LINK },
                                new int[] { R.id.link, R.id.name });

                        setListAdapter(adapter);
                    }
                });

            }

        }

}
R.layout.list_项,它是listview的不同.xml布局。
你们能帮我解决这个问题吗?提前谢谢

我觉得与其使用SimpleAdapter,不如扩展BaseAdapter,并将您正在使用的文本视图设置为linkify。这样它就会自动获得单击。 请参阅:


将此行放到您的文本视图中

android:autoLink=“web”


我希望这将解决您的查询问题

我也想在我的列表适配器上创建一个可链接的文本视图,所以我使用了:

    Linkify.addLinks(textViewLocationPhone, Linkify.PHONE_NUMBERS);
    textViewLocationPhone.setLinksClickable(true);

它成功了。

我建议您制作自定义适配器。使R.layout.list_项中的文本视图可单击并可聚焦。看到这个答案,这将帮助你解决你的问题。在自定义适配器的构造函数中传递活动而不是上下文
    Linkify.addLinks(textViewLocationPhone, Linkify.PHONE_NUMBERS);
    textViewLocationPhone.setLinksClickable(true);