gpt4 book ai didi

android - 当我单击“ ListView 内容”时,它们是通过不在我的应用程序中的 Web 浏览器打开的

转载 作者:行者123 更新时间:2023-11-29 18:05:10 24 4
gpt4 key购买 nike

我的 Android 应用程序在 ListView 中显示我网站的 RSS 提要。起初,我的应用程序在 ListView 中显示最新的 20 个帖子的标题后显示“正在加载”页面。当我单击主题名称时,主题正在使用不在我的应用程序中的 Web 浏览器打开。

this is my MainActivity.java

public class MainActivity extends ListActivity {

private MyFeed myRssFeed = null;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

new MyTask().execute();

}
private class MyTask extends AsyncTask<Void, Void, Void>{

@Override
protected Void doInBackground(Void... arg0) {
try {
URL rssUrl = new URL("http://mywindows8.org/windows-8-tutorials/feed/");
SAXParserFactory mySAXParserFactory = SAXParserFactory.newInstance();
SAXParser mySAXParser = mySAXParserFactory.newSAXParser();
XMLReader myXMLReader = mySAXParser.getXMLReader();
MyWindows myRSSHandler = new MyWindows();
myXMLReader.setContentHandler(myRSSHandler);
InputSource myInputSource = new InputSource(rssUrl.openStream());
myXMLReader.parse(myInputSource);

myRssFeed = myRSSHandler.getFeed();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (ParserConfigurationException e) {
e.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

return null;
}

@Override
protected void onPostExecute(Void result) {
if (myRssFeed!=null)
{

ArrayAdapter<Topic> adapter =
new ArrayAdapter<Topic>(getApplicationContext(), R.layout.custom_list_item,myRssFeed.getList());
setListAdapter(adapter);

}else{

TextView textEmpty = (TextView)findViewById(android.R.id.empty);
textEmpty.setText("No Feed Found!");
}

super.onPostExecute(result);
}

}

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {

Uri feedUri = Uri.parse(myRssFeed.getItem(position).getLink());
Intent myIntent = new Intent(Intent.ACTION_VIEW, feedUri);
startActivity(myIntent);

}

}

这是 activity_main.xml 文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
android:textSize="20sp"
android:background="@layout/button5"
android:orientation="vertical"
android:textColor="#D5D5D5"
android:gravity="center"/>

<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:textColor="#000000"
android:background="@layout/back2"
android:orientation="vertical"
android:divider="@layout/list_divider"
android:dividerHeight="2dp"


/>

<TextView
android:id="@android:id/empty"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/loading"
android:gravity="center"
/>
</LinearLayout>

最佳答案

这应该有效:

ListView listView = new ListView(this);

listView.setOnItemClickListener(new OnItemClickListener() {

@Override
public void onItemClick(AdapterView<?> arg0, View listItemView, int positionOfItem, long idOfItem) {
// Here you put what you want to do when a listItem is clicked
Intent k = new Intent(this, Contenturl.class);
k.putExtra(org.core.mywindows8.Contenturl.URL, "http://mywindows8.org/windows-8-themes/");
MainActivity.this.finish();
startActivity(k);

}
});

更多文档:

关于android - 当我单击“ ListView 内容”时,它们是通过不在我的应用程序中的 Web 浏览器打开的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13731708/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com