amhacker
چهارشنبه 11 تیر 1393, 20:33 عصر
سلام دوستان من میخوام اولا این که با لیست ویو موضوعات رو نمایش بدم با کلیک روی هر موضوع مطالب هر موضوع باز در لیست ویو (چون نهایت حجم هر مطلب یکی دو خط هست مشابه برنامه های پیامک ) مطلاب هم تو دیتابیس قرار دارند که فرضا هر 20 مطلب یک موضوع داره
الان میخواستم بدونم این کار شدنی هست ؟؟
دوم اینکه کد لیست ویو تو در تو چی میشه ؟؟
کدی که من واسه صفحه ی اصلی استفاده کردم اینه
میخوام موضوعات تواین صفحه باشه با انتخاب هر موضوع از دیتابیس مطالب تو لیست ویو نمایش داده بشه
دوستانی که میتونند راهنمایی کنند ممنون میشم تجربه شون رو در اختیارم بزارن چند روزی هست که دارم سرچ میکنم ولی به نتیجه نمی رسم
public class MainActivity extends ListActivity {
DBAdapter db;
List<Matlab> matlabha;
ListView lst;
boolean isAll;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
isAll =true;
lst = getListView();
db = new DBAdapter(getBaseContext());
db.open();
matlabha = db.getAllContacts();
if (matlabha.size() == 0) {
String destPath = "/data/data/" + getPackageName() + "/databases";
try {
CopyDB(getBaseContext().getAssets().open("mydb"),
new FileOutputStream(destPath + "/matlabha"));
matlabha = db.getAllContacts();
refreshDisplay();
Log.i(DBAdapter.TAG, matlabha.size() + "= tedad matlabha");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
} else {
refreshDisplay();
}
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
Matlab matlab = matlabha.get(position);
Intent next = new Intent(this, ShowMatlab.class);
next.putExtra("thisMatlab", matlab);
startActivity(next);
}
public void CopyDB(InputStream inputStream, OutputStream outputStream)
throws IOException {
byte[] buffer = new byte[1024];
int length;
while ((length = inputStream.read(buffer)) > 0) {
outputStream.write(buffer, 0, length);
}
inputStream.close();
outputStream.close();
}
public void refreshDisplay() {
Log.i(DBAdapter.TAG, matlabha.size() + "= tedad matlabha");
ArrayAdapter<Matlab> adapter = new MatlabAdapter(this, matlabha);
setListAdapter(adapter);
}
@Override
protected void onResume() {
super.onResume();
if (isAll) {
matlabha = db.getAllContacts();
}else {
matlabha=db.findFAVContacts();
}
refreshDisplay();
}
}
الان میخواستم بدونم این کار شدنی هست ؟؟
دوم اینکه کد لیست ویو تو در تو چی میشه ؟؟
کدی که من واسه صفحه ی اصلی استفاده کردم اینه
میخوام موضوعات تواین صفحه باشه با انتخاب هر موضوع از دیتابیس مطالب تو لیست ویو نمایش داده بشه
دوستانی که میتونند راهنمایی کنند ممنون میشم تجربه شون رو در اختیارم بزارن چند روزی هست که دارم سرچ میکنم ولی به نتیجه نمی رسم
public class MainActivity extends ListActivity {
DBAdapter db;
List<Matlab> matlabha;
ListView lst;
boolean isAll;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
isAll =true;
lst = getListView();
db = new DBAdapter(getBaseContext());
db.open();
matlabha = db.getAllContacts();
if (matlabha.size() == 0) {
String destPath = "/data/data/" + getPackageName() + "/databases";
try {
CopyDB(getBaseContext().getAssets().open("mydb"),
new FileOutputStream(destPath + "/matlabha"));
matlabha = db.getAllContacts();
refreshDisplay();
Log.i(DBAdapter.TAG, matlabha.size() + "= tedad matlabha");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
} else {
refreshDisplay();
}
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
Matlab matlab = matlabha.get(position);
Intent next = new Intent(this, ShowMatlab.class);
next.putExtra("thisMatlab", matlab);
startActivity(next);
}
public void CopyDB(InputStream inputStream, OutputStream outputStream)
throws IOException {
byte[] buffer = new byte[1024];
int length;
while ((length = inputStream.read(buffer)) > 0) {
outputStream.write(buffer, 0, length);
}
inputStream.close();
outputStream.close();
}
public void refreshDisplay() {
Log.i(DBAdapter.TAG, matlabha.size() + "= tedad matlabha");
ArrayAdapter<Matlab> adapter = new MatlabAdapter(this, matlabha);
setListAdapter(adapter);
}
@Override
protected void onResume() {
super.onResume();
if (isAll) {
matlabha = db.getAllContacts();
}else {
matlabha=db.findFAVContacts();
}
refreshDisplay();
}
}