Невозможно вставить больше значений в listview в базе данных sqlite(android studio).
Я пытаюсь вставить некоторые значения в базу данных SQLite в android.
Значения вставлялись раньше, теперь, когда я запускаю свое приложение, оно не показывает значения, которые я пытаюсь добавить.
Мое приложение имеет в основном функцию поиска в панели действий.
Основная деятельность прилагается ниже.
Что я уже пробовал:
package com.admin.search; import android.annotation.TargetApi; import android.app.SearchManager; import android.content.Context; import android.database.Cursor; import android.os.Build; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.SearchView; import android.util.Log; import android.view.Menu; import android.widget.ListView; import android.widget.Toast; public class MainActivity extends AppCompatActivity { private CustomAdapter customAdapter; ListView listView; Cursor cursor; StationRepo stationRepo ; private final static String TAG= MainActivity.class.getName().toString(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(com.admin.fyp.R.layout.activity_main); stationRepo = new StationRepo(this); cursor=stationRepo.getStudentList(); customAdapter = new CustomAdapter(MainActivity.this, cursor, 0); listView = (ListView) findViewById(com.admin.fyp.R.id.lstStudent); listView.setAdapter(customAdapter); if(cursor==null) insertDummy(); } private void insertDummy(){ Station station= new Station(); station.stop ="Bus Stop: Youhana Abaad\nDistance: 5.0 Km"; station.name="Ataari Saroba"; stationRepo.insert(station); stationRepo = new StationRepo(this); station.stop ="Bus Stop: Bhatti Chowk\nDistance: 4.1 Km"; station.name="Azaadi Chowk"; stationRepo.insert(station); stationRepo = new StationRepo(this); station.stop ="Bus Stop: Katchery\nDistance: 1.9 Km"; station.name="Bhatti Chowk"; stationRepo.insert(station); stationRepo = new StationRepo(this); station.stop ="Bus Stop: Qaddafi Stadium\nDistance:0.8 km"; station.name="Canal"; stationRepo.insert(station); stationRepo = new StationRepo(this); station.stop ="Kamahan\nDistance: 2.1 Km"; station.name="Chungi Amar Sidhu"; stationRepo.insert(station); stationRepo = new StationRepo(this); station.stop ="MAO College\nDistance: 1.7 Km"; station.name="Civil Secretariat"; stationRepo.insert(station); stationRepo = new StationRepo(this); station.stop ="Bus Stop: Gajjumata\nDistance: 0.9 Km"; station.name="Dulu Khurd"; stationRepo.insert(station); stationRepo = new StationRepo(this); station.stop ="Bus Stop: Dullu Khurd\nDistance: 0.9 Km"; station.name="Gajjumata"; stationRepo.insert(station); stationRepo = new StationRepo(this); station.stop ="Bus Stop: Chungi Amar Sidhu\nDistance: 2.5 Km"; station.name="Ghazi Chowk"; stationRepo.insert(station); stationRepo = new StationRepo(this); station.stop ="Bus Stop: Canal\nDistance: 1.6 Km"; station.name="Ichra"; stationRepo.insert(station); stationRepo = new StationRepo(this); station.stop ="Bus Stop: Qainchi\nDistance: 6.0 Km"; station.name="Itefaq Hospital"; stationRepo.insert(station); stationRepo = new StationRepo(this); station.stop ="Bus Stop: Qartabah Chowk\nDistance: 2.0 Km"; station.name="Janazgah"; stationRepo.insert(station); stationRepo = new StationRepo(this); station.stop ="Bus Stop: Model Town\nDistance: 4.3 Km"; station.name="Kalma Chowk"; stationRepo.insert(station); stationRepo = new StationRepo(this); station.stop ="Bus Stop: Ataari Saroba\nDistance: 2.9 Km"; station.name="Kamahan"; stationRepo.insert(station); stationRepo = new StationRepo(this); station.stop ="Bus Stop: Civil Secretariat\nDistance: 0.9 Km"; station.name="Katchery"; stationRepo.insert(station); stationRepo = new StationRepo(this); station.stop ="Bus Stop: Janazgah\nDistance: 2.0 Km"; station.name="MAO College"; stationRepo.insert(station); stationRepo = new StationRepo(this); station.stop ="Bus Stop: Naseerahbad\nDistance: 3.7 Km"; station.name="Model Town"; stationRepo.insert(station); stationRepo = new StationRepo(this); station.stop ="Bus Stop: Itefaq Hospital\nDistance: 4.1 Km"; station.name="Naseerahbad"; stationRepo.insert(station); stationRepo = new StationRepo(this); station.stop ="Bus Stop: Timber Market\nDistance: 0.8 Km"; station.name="Niazi Chowk"; stationRepo.insert(station); stationRepo = new StationRepo(this); station.stop ="Bus Stop: Kalma Chowk\nDistance: 3.0 Km"; station.name="Qaddafi Stadium"; stationRepo.insert(station); stationRepo = new StationRepo(this); station.stop ="Bus Stop: Ghazi Chowk\nDistance: 1.1 Km"; station.name="Qainchi"; stationRepo.insert(station); stationRepo = new StationRepo(this); station.stop ="Bus Stop: Shama\nDistance: 1.2 Km"; station.name="Qartaba Chowk"; stationRepo.insert(station); stationRepo = new StationRepo(this); station.stop ="Bus Stop: Niazi Chowk\nDistance: 1.9 Km"; station.name="Shahdra"; stationRepo.insert(station); stationRepo = new StationRepo(this); station.stop ="Bus Stop: Ichra\nDistance: 0.7 Km"; station.name="Shama"; stationRepo.insert(station); stationRepo = new StationRepo(this); station.stop ="Bus Stop: Azaadi Chowk\nDistance: 2.2 Km"; station.name="Timber Market"; stationRepo.insert(station); stationRepo = new StationRepo(this); station.stop ="Bus Stop: Dulu Khurd\nDistance: 0.9 Km"; station.name="Youhana Abaad"; stationRepo.insert(station); //Feeder Routes. stationRepo = new StationRepo(this); station.stop="Bus Stop: Bhatti Chowk\nDistance: 0.9 Km"; station.name="Railway Station(FR-01)"; stationRepo.insert(station); stationRepo = new StationRepo(this); station.stop="Bus Stop: Bhatti Chowk\nDistance: 0.9 Km"; station.name="Samanabad Morr(FR-02)"; stationRepo.insert(station); stationRepo = new StationRepo(this); station.stop="Bus Stop: Shahdara\nDistance: 0.9 Km"; station.name="Railway Station(FR-03)"; stationRepo.insert(station); stationRepo = new StationRepo(this); station.stop="Bus Stop: Chungi Amar Sidhu\nDistance: 0.9 Km"; station.name="R.A Bazar(FR-04)"; stationRepo.insert(station); stationRepo = new StationRepo(this); station.stop="Bus Stop: Bhatti Chowk\nDistance: 0.9 Km"; station.name="Shadbagh Underpass(FR-05)"; stationRepo.insert(station); stationRepo = new StationRepo(this); station.stop="Bus Stop: Raj Ghar Chowk\nDistance: 0.9 Km"; station.name="Babu Sabu(FR-06)"; stationRepo.insert(station); } @Override public void onResume(){ super.onResume(); } @Override @TargetApi(Build.VERSION_CODES.HONEYCOMB) public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(com.admin.fyp.R.menu.options_menu, menu); if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { SearchManager manager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); SearchView search = (SearchView) menu.findItem(com.admin.fyp.R.id.search).getActionView(); search.setSearchableInfo(manager.getSearchableInfo(getComponentName())); search.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String s) { Log.d(TAG, "onQueryTextSubmit "); cursor=stationRepo.getStudentListByKeyword(s); if (cursor==null){ Toast.makeText(MainActivity.this,"No records found!",Toast.LENGTH_LONG).show(); }else{ Toast.makeText(MainActivity.this, cursor.getCount() + " records found!",Toast.LENGTH_LONG).show(); } customAdapter.swapCursor(cursor); return false; } @Override public boolean onQueryTextChange(String s) { Log.d(TAG, "onQueryTextChange "); cursor=stationRepo.getStudentListByKeyword(s); if (cursor!=null){ customAdapter.swapCursor(cursor); } return false; } }); } return true; } }
Richard MacCutchan
Пожалуйста, правильно отформатируйте свой код и покажите, где возникает проблема.
Member 13390616
Я создал объект, пытаясь вставить значения в listView в базе данных SQLite.
Не удалось вставить значения из
//Подъездных Путей.
stationRepo = новый StationRepo(это);
station.stop="автобусная остановка: Bhatti Chowk\nDistance: 0.9 Km";
station.name="железнодорожная станция(FR-01)";
stationRepo.insert(станция);
чтобы владеть собой..