2011-11-27 6 views
0

누군가이 아주 간단한 질문으로 나를 도울 수 있습니까? 나는 아주 초보자입니다. 내 목록보기의 각 항목에 대한 가사 보는 방법각 목록보기 항목에 대한 텍스트 표시

:

이것은 listview

String[] items = {"Silent night", "Deck The hall","Feliz navidad","Jingle bell", "song 4","song 5"}; 

질문에 대한 내 문자열? 내 가사를 원본에 저장합니다.

세부 사항 :

내가 main.xml에 주요 textview 4 버튼 (크리스마스, 힐송, 버튼 3 버튼 4)을 가지고있다. 크리스마스 버튼을 클릭하면 listview에 크리스마스 노래 목록이있는 크리스마스 레이아웃으로 전환됩니다. 제목을 클릭하면 main.xml을 다시 참조하고 가사를 주 textview에서 봅니다. 사용의 ListView

답변

1

확인 좋은 예는 밖으로 http://www.vogella.de/articles/AndroidListView/article.html은 기본적으로 당신은 ListActivity를 확장하는 새로운 클래스를 만들 것이다.

import android.app.ListActivity; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.ArrayAdapter; 
import android.widget.ListView; 
import android.widget.Toast; 

public class MyListActivity extends ListActivity { 
    public void onCreate(Bundle icicle) { 
     super.onCreate(icicle); 
     String[] values = new String[] { "song1", "song2", "song3", 
       "song4" }; 
     ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, 
       android.R.layout.simple_list_item_1, values); 
     setListAdapter(adapter); 
    } 

} 

그런 다음 사용자가 목록 항목을 클릭 할 때 확인하고 다음에 포장 및 가사입니다하여 다음 활동에 의도를 통해 전송해야합니다.

@Override 
     protected void onListItemClick(ListView l, View v, int position, long id) { 
      String item = (String) getListAdapter().getItem(position); 
      Intent intent = new Intent(this, Lyrics.class); 
        intent.putExtra("song", item); //item is the listitem ie. song1, etc. 
        startActivity(intent); 
     } 

마지막으로 가사 클래스에서 추가 정보를 검색해야합니다.

@Override 
    public void onCreate(Bundle icicle) { 
     super.onCreate(icicle); 
     Bundle extras = getIntent().getExtras(); 
     if(extras != null) { 
     String song = extras.getString("song"); 
     } 
... 
} 

이제 노래 가사 활동에 포함되어 있으며, 거기에서 가져올 수 있습니다. 나는 거의 모든 응용 프로그램을 작성했습니다 .... x_X

+0

감사합니다. bwoogie –

관련 문제