title: Android: How to display string on textview from console
body: <p>I'm trying to display string on the textview. I'm succesfully able to print it on the console from database, but I'm not able to figure out how to print all the strings on different different textviews. Here is my code:</p>
  
  <p>MainActivity.java</p>
  
  <pre><code>public class MainActivity extends Activity implements OnClickListener {
  
  EditText search;
  Button insert;
  TextView txt1, txt2, txt3, txt4, txt5;
  DatabaseHandler db;
  List&lt;History&gt; history;
  
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      db = new DatabaseHandler(this);
  
      search = (EditText) findViewById(R.id.search_word);
      insert = (Button) findViewById(R.id.insert);
      txt1 = (TextView) findViewById(R.id.txt1);
      txt2 = (TextView) findViewById(R.id.txt2);
      txt3 = (TextView) findViewById(R.id.txt3);
      txt4 = (TextView) findViewById(R.id.txt4);
      txt5 = (TextView) findViewById(R.id.txt5);
  
      insert.setOnClickListener(this);
  
      history = db.getAllHistory();
  }
  
  public void onClick(View v) {
      db.addHistory(new History(search.getText().toString(), null));
      Toast.makeText(getApplicationContext(),
              "Inserted: " + search.getText().toString(), Toast.LENGTH_LONG)
              .show();
  }
  
  @Override
  protected void onStart() {
      super.onStart();
      List&lt;History&gt; history = db.getAllHistory();
      for (History cn : history) {
          String log = "Search Strings: " + cn.getName();
          Log.d("Search Strings: ", log);
      }
  }
  }
  </code></pre>
  
  <p>This is my activity in which I'm bringing my all database value on onStart() function. Now here I have to set all the data coming from database on the textview. Here is my DabaseHandler class in which I'm taking out each row.</p>
  
  <p>DatabaseHandler.java</p>
  
  <pre><code>public class DatabaseHandler extends SQLiteOpenHelper {
  
  private static final int DATABASE_VERSION = 1;
  
  private static final String DATABASE_NAME = "historyManager";
  
  private static final String TABLE_HISTORY = "histories";
  
  private static final String KEY_NAME = "history";
  
  public DatabaseHandler(Context context) {
      super(context, DATABASE_NAME, null, DATABASE_VERSION);
  }
  
  @Override
  public void onCreate(SQLiteDatabase db) {
      String CREATE_HISTORY_TABLE = "CREATE TABLE " + TABLE_HISTORY + "("
              + KEY_NAME + " TEXT" + ")";
      db.execSQL(CREATE_HISTORY_TABLE);
  }
  
  @Override
  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
      // Drop older table if existed
      db.execSQL("DROP TABLE IF EXISTS " + TABLE_HISTORY);
  
      onCreate(db);
  }
  
  void addHistory(History history) {
      SQLiteDatabase db = this.getWritableDatabase();
  
      ContentValues values = new ContentValues();
      values.put(KEY_NAME, history.getName());
  
      db.insert(TABLE_HISTORY, null, values);
      db.close();
  }
  
  History getHistory(int id) {
      SQLiteDatabase db = this.getReadableDatabase();
  
      Cursor cursor = db.query(TABLE_HISTORY, new String[] { KEY_NAME },
              "=?", new String[] { String.valueOf(id) }, null, null, null,
              null);
      if (cursor != null)
          cursor.moveToFirst();
  
      History history = new History(Integer.parseInt(cursor.getString(0)),
              cursor.getString(1), cursor.getString(2));
      return history;
  }
  
  public List&lt;History&gt; getAllHistory() {
      List&lt;History&gt; historyList = new ArrayList&lt;History&gt;();
  
      String selectQuery = "SELECT  * FROM " + TABLE_HISTORY;
  
      SQLiteDatabase db = this.getWritableDatabase();
      Cursor cursor = db.rawQuery(selectQuery, null);
  
      if (cursor.moveToFirst()) {
          do {
              History contact = new History();
              contact.setName(cursor.getString(0));
              historyList.add(contact);
          } while (cursor.moveToNext());
      }
  
      return historyList;
  }
  
  public int updateHistory(History history) {
      SQLiteDatabase db = this.getWritableDatabase();
  
      ContentValues values = new ContentValues();
      values.put(KEY_NAME, history.getName());
      return db.update(TABLE_HISTORY, values, KEY_NAME + " = ?",
              new String[] { String.valueOf(history.getName()) });
  }
  
  public void deleteHistory(History history) {
      SQLiteDatabase db = this.getWritableDatabase();
      db.delete(TABLE_HISTORY, KEY_NAME + " = ?",
              new String[] { String.valueOf(history.getName()) });
      db.close();
  }
  
  public int getHistoryCount() {
      String countQuery = "SELECT  * FROM " + TABLE_HISTORY;
      SQLiteDatabase db = this.getReadableDatabase();
      Cursor cursor = db.rawQuery(countQuery, null);
      cursor.close();
  
      return cursor.getCount();
  }
  }
  </code></pre>
  
  <p>Please help in getting data printed on the textview. On the Log.d I can see all my data coming, one after another. But I'm not able to print all the data.</p>