我阅读了很多关于复制项目的内容,但对我来说没有解决方案, 还有4天的搜索,没有回答我的工作 我希望能找到答案的人
这是活动类中的类适配器
private class TestAdapter extends ArrayAdapter{
public TestAdapter(Context context) {
super(context, R.layout.single_row_workout, R.id.text_title , titles);
}
@NonNull
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row=convertView;
MyHolderview_BA holderview=null;
if (row==null){
row = getLayoutInflater().inflate(R.layout.single_row_workout , parent , false);
holderview = new MyHolderview_BA(row);
row.setTag(holderview);
}else{
holderview = (MyHolderview_BA) row.getTag();
}
holderview.tv_title.setText(titles[position]);
holderview.tv_desc.setText( desc[position] );
return row;
}
}
class MyHolderview_BA{
TextView tv_title,tv_desc;
MyHolderview_BA(View row){
tv_title = (TextView) row.findViewById(R.id.text_title);
tv_desc = (TextView) row.findViewById(R.id.text_desc);
}
}
//**strong text**
这里是来自另一个意图的标题和desc数组
public class MyDay_Program extends AppCompatActivity {
ListView listView;
TextView address_TV;
String Address="";
String titles[];
String desc[];
String day;
// MyBAseAdapter myBAseAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_day__program);
Address= getIntent().getExtras().getString("Address");
titles = getIntent().getExtras().getStringArray(StaticsVariables.title);
desc = getIntent().getExtras().getStringArray(StaticsVariables.Desc);
day = getIntent().getExtras().getString("day");
address_TV = (TextView) findViewById(R.id.textview_myday_program);
address_TV.setText("Address");
listView = (ListView) findViewById(R.id.myday_program_listview);
//myBAseAdapter = new MyBAseAdapter();
listView.setAdapter( new TestAdapter(this) );
//myBAseAdapter.Cleardata();
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int positin, long l) {
Intent intent = new Intent(MyDay_Program.this , StartWorkout.class);
intent.putExtra( StaticsVariables.title , titles[positin] );
intent.putExtra( StaticsVariables.Desc , desc[positin] );
intent.putExtra( StaticsVariables.image , R.drawable.fitness );
startActivity(intent);
}
});
}
这是Go活动并将数据放入的意图
myDataBase.Select_All_DAY(programs [position])从DATABASE SQLITE中检索数据表
titles和desc是arraylists,Address是String
。
。
Intent intent = new Intent(getActivity(),MyDay_Program.class);
MyDataBase myDataBase = new MyDataBase(getActivity());
Cursor cursor = myDataBase.Select_All_DAY(programs[position]);
//Log.d("testdb",programs[position]);
if (cursor != null && cursor.moveToFirst()) { //if day contain Workouts
do {
titles.add(cursor.getString(cursor.getColumnIndex("name")));
desc.add(cursor.getString(cursor.getColumnIndex("desc")));
//images.add( cursor.getInt( cursor.getColumnIndex("image") ) );
Log.d("testdb", titles.get(0) + " : " + desc.get(0));
} while (cursor.moveToNext());
cursor.close();
String[] Mytitles = titles.toArray(new String[titles.size()]);
String[] Mydesc = desc.toArray(new String[desc.size()]);
intent.putExtra("Address", programs[position]);
intent.putExtra(StaticsVariables.title, Mytitles);
intent.putExtra(StaticsVariables.Desc, Mydesc);
//intent.putExtra("day", programs[position]);
startActivity(intent);