如何獲取列表視圖的選定項目以共享相關文本?在社交網站上共享來自列表視圖的新聞鏈接
這裏是我的代碼,我已經試過,但它不工作
public class MainActivity extends ListActivity {
TextView content;
ListView list;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// list = (ListView) findViewById(R.id.list1);
content = (TextView) findViewById(R.id.output);
// listView = (ListView) findViewById(R.id.list);
String[] values = new String[] { "Android Example ListActivity",
"Adapter implementation", "Simple List View With ListActivity",
"ListActivity Android", "Android Example",
"ListActivity Source Code",
"ListView ListActivity Array Adapter",
"Android Example ListActivity" };
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, values);
// Assign adapter to List
setListAdapter(adapter);
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
// ListView Clicked item index
int itemPosition = position;
// ListView Clicked item value
String itemValue = (String) l.getItemAtPosition(position);
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
"Subject Here");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, itemValue);
startActivity(Intent.createChooser(sharingIntent, "Share via"));
}
}
您從XML中獲取數據並將其存儲到ArrayList中? –
@M D取自rss – poojagupta
@PG並存儲在哪裏? –