解决方案 »

  1.   

    你想表达什么意思?我看不大明白。
    http://download.csdn.net/detail/u012137924/8412899
    这个是我前不久写个一个DEMO,关于ListView的,你下载看看,或许有帮助,下班了先,呵呵。
      

  2.   

    就是给listview设置上下文菜单后,怎样在菜单项上获得item的内容
      

  3.   

    长按listview的Item,弹出一个窗口,不一定要是menu,这个窗口的布局随你布局,里面的内容就是获取到的Item的内容
      

  4.   

    直接获取当前LIST对应ITEM的内容就好了。然后设置一个显示隐藏或者对话框都行。不一定要用menu  menu现在用的很少 。
      

  5.   

     menu有标题吗?弹的应该是dialo吧?
      

  6.   

    lv.setOnItemLongClickListener(new OnItemLongClickListener() { @Override
    public boolean onItemLongClick(AdapterView<?> parent, View v,
    int position, long arg3) {
    // TODO Auto-generated method stub
    tv = (TextView) v.findViewById(R.id.item_tv);
    Toast.makeText(getApplication(), tv.getText().toString(), 1).show();
    return true;
    }
    });
    比较笨的方法就这样了。
      

  7.   

    这是个什么需求?还是不大清楚。
    按照你的描述, 你所说的菜单是指Menu还是指ListView的Item?
    是Menu的话,直接用容器吧,ArrayList等都可以;
    是Item的话,建议你还是下载我之前写的那个DEMO吧,那里面有详细的注释,那个DEMO是曾经给CSDN上的一个朋友写的关于如何在适配器里面跳转到不同的Activity,因为涉及到Item的子布局控件的点击,所以用OnItemClickListener是解决不了的,呵呵。
      

  8.   

    。恍然大悟,有点明白你的意思了。你直接说想获取手机里的歌曲名不就好了?汗。
    用Environment.getExternalStorageDirectory().getpath+"/MUSIC/"这个是获取你手机上的MUSIC目录的路径,哎,算了,明天早上去给你写段代码,你就清楚了。现在不太想动,呵呵。
      

  9.   

    兑现昨天的话,现在贴上代码,已测试,No Problem,呵呵。public class TestListSongName extends Activity {
    private static final String TAG = "TestListSongName";
    private ListView listViewSongName;
    private List<String> list; @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.list_song_name); initView();
    } private void initView() {
    listViewSongName = (ListView) this.findViewById(R.id.listSongName);
    // 获取音乐文件夹路径
    String path = Environment.getExternalStorageDirectory().getPath()
    + "/MUSIC/";
    Log.e(TAG, "path == " + path); /**
     * 新建一个文件夹把歌曲列入,然后For循环一次取出各文件的文件名并添加到list列表中,
     * 当然这只是最简单的处理,没有考虑二级和更深级的文件夹.当然如果要做音乐播放器的话
     * 这里需要优化,不过,只是获取MUSIC文件夹下的歌曲名的话,用这个足以。呵呵。
     */
    // //简写
    // File[] songNameFiles = new File(path).listFiles();
    File file = new File(path);
    File[] songNameFiles = file.listFiles();
    list = new ArrayList<String>(); for (int i = 0; i < songNameFiles.length; i++) {
    list.add(songNameFiles[i].getName());
    } Log.e(TAG, "list {" + list + "}"); listViewSongName.setAdapter(new ListSongNameAdapter(this, list));
    } // 一个通常写法的适配器。
    public class ListSongNameAdapter extends BaseAdapter {
    private Context context;
    private List<String> list; public ListSongNameAdapter(Context context, List<String> list) {
    this.context = context;
    this.list = list;
    } @Override
    public int getCount() {
    return list.size();
    } @Override
    public Object getItem(int position) {
    return list.get(position);
    } @Override
    public long getItemId(int position) {
    return position;
    } @Override
    public View getView(int position, View convertView, ViewGroup parent) {
    ViewCache viewCache = null; if (convertView == null) {
    viewCache = new ViewCache();
    convertView = LayoutInflater.from(context).inflate(
    R.layout.list_song_name_item, null);
    viewCache.textSongName = (TextView) convertView
    .findViewById(R.id.songName);
    convertView.setTag(viewCache);
    } else {
    viewCache = (ViewCache) convertView.getTag();
    } String songName = list.get(position).toString();
    viewCache.textSongName.setText(songName); return convertView;
    } class ViewCache {
    TextView textSongName;
    }
    }
    }list_song_name.xml<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context=".TestListSongName" >    <ListView
            android:id="@+id/listSongName"
            android:layout_width="match_parent"
            android:layout_height="match_parent" /></RelativeLayout>list_song_name_item.xml<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >    <TextView
            android:id="@+id/songName"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="10dp"
            android:textSize="25sp" /></RelativeLayout>