我有一個「電影」類和公共職能的getName(),但功能不返回任何東西,和logcat的只是空白。公共功能不能正常工作
public class movie {
public String name45;
int dvd_no ;
public void addData(String name1 , int dvd_no1)
{
this.name45=name1 ;
this.dvd_no = dvd_no1 ;
Log.d("constructor name1", name1);
Log.d("constructor name45", name45);
}
public String getName()
{
return name45 ;
}
}
這是一個使用此方法的活動 - 該列表始終有空白條目。
public class MoviesList extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.movieslist);
ListView lvAllMoviesList = (ListView)findViewById(R.id.allmovieslist);
ArrayList<String> moviesNames = new ArrayList<String>();
// go through list of members and compare name with given name
for(movie movie : MovieReg_activity.movies) {
String name = movie.getName();
Log.d("Movie Name list", movie.getName());
moviesNames.add(name);
}
ArrayAdapter<String> AllMovieList = new ArrayAdapter<String>(MoviesList.this,android.R.layout.simple_list_item_1, moviesNames);
lvAllMoviesList.setAdapter(AllMovieList);
}
}
其產生的對象,並添加值,它
public class MovieReg_activity extends Activity {
public static List<movie> movies = new ArrayList<movie>();
String movName ;
int dvdNo ;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.mov_reg_layout);
EditText etmovie_name = (EditText)findViewById(R.id.etmovname);
EditText etdvd_no = (EditText)findViewById(R.id.etdvds);
Button btMovie_submit = (Button)findViewById(R.id.btmovsubmit);
movName= etmovie_name.getText().toString();
// dvdNo = Integer.parseInt(etdvd_no.getText().toString()); // to string then to int :)
btMovie_submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int x=0 ;
movie movie = new movie() ;
movie.addData(movName, dvdNo);
movies.add(x,movie);
x++ ;
int size =movies.size() ;
Toast.makeText(MovieReg_activity.this, "no of movies added :"+size , Toast.LENGTH_SHORT).show();
}
});
}
}
我們如何調試這解決了嗎?我們不知道你是如何使用它的。 –
@DaveNewton抱歉..我將編輯後 – Fawzinov
@DaveNewton我的意思通過的logcat來測試一下吧! – Fawzinov