Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
197 views
in Technique[技术] by (71.8m points)

java - 无法设置ActionView意图(Can't setup the ActionView intent)

I would like to have some possibility in my app.

(我想在我的应用中有一些可能性。)

I'd like to open browser by link which will be get from json response when user will click on some item in ListView.

(我想通过链接打开浏览器,当用户单击ListView中的某些项时,该链接将从json响应中获取。)

I've already did some work, and I have some links when user tap on some item, but I can't make it work, to open the browser.

(我已经做了一些工作,当用户点击某些项目时我有一些链接,但是我无法使其正常工作以打开浏览器。)

How I may do it?

(我该怎么做?)

MainActivity

(主要活动)

    ArrayList<Earthquake> earthquakes = QueryUtils.extractEarthquakes();
    ListView listView = (ListView) findViewById(R.id.list);
    EarthquakeAdapter adapter = new EarthquakeAdapter(this, earthquakes);
    listView.setAdapter(adapter);

Adapter class

(转接器类别)

public EarthquakeAdapter(Context context, List<Earthquake> list ) {
    super(context, 0, list);
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View listView = convertView;

    if (listView == null) {
        listView = LayoutInflater.from(getContext()).inflate(R.layout.list_items, parent, 
  false);
}

...

listView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Toast.makeText(getContext(),pojo.getUrl(),Toast.LENGTH_SHORT).show();
        }
    });
    return listView;
}
  ask by Aws translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can use below code in your click listener:

(您可以在点击监听器中使用以下代码:)

Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(pojo.getUrl()));
getContext().startActivity(i);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...