Make the corresponding array match multiple rows, followed by the same row id

I have a database in which identifiers change after several lines, then I would change in some lines. What I want, the same values ​​will be populated with a list in one line, then when the identifiers are the same, they are all on the same line. And thus, the following lines are filled with the same lines that have the same identifiers.

My database columns and rows are as follows:


Verse_id ------- words_id ---------- words_ar ------ translate_bn -

1-----------------------1---------------Mamun-----------Assistant--- 1-----------------------2--------------- Salam------------Operator------ 1-----------------------3---------------John--------------Assistant------ 2 ----------------------1--------------- Smith-------------Manager------ 2-----------------------2---------------Roger--------------Director-------- 3-----------------------1---------------Qoel---------------Helper---------- 3-----------------------2---------------Saki---------------Mechanics----- 3-----------------------3----------------Ali-----------------Getman---------- 

I want this database to be in three lines: (listview):

 1. Mamun. Salam John Assistant. Operator. Assistant ------------------------------------------------------------------ 2. Smith. Roger. Manager. Director ------------------------------------------------------------------ 3. Qoel. Saki. Ali. Helper. Mechanics. Getman 

I tried in two ways: First:

 private static final String PRIMARY_ID = "_id"; private static final String TABLE_NAME = "bywords"; private static final String FRIEND_ID = "verse_id"; private static final String WORDS_ID = "words_id"; private static final String WORDS_bN = "translate_bn"; private static final String WORDS_AR = "words_ar"; private SQLiteDatabase database; private ArrayList<String> friends; private ArrayList<String> trans1; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main2); mContext = this; ExternalDbOpenHelper dbOpenHelper = new ExternalDbOpenHelper(this, DB_NAME); database = dbOpenHelper.openDataBase(); Cursor cursor = database.rawQuery("SELECT * FROM bywords", null); ListView list4=(ListView)findViewById(R.id.list4) ; String[] from = {WORDS_AR }; // _id mandatory int[] to = new int[]{R.id.alquran_text}; CursorAdapter adapter = new SimpleCursorAdapter( mContext, R.layout.list_item, cursor, from, to, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER); list4.setAdapter(adapter); 

And the second:

  trans1 = new ArrayList<String>(); String[] allColumns2 = new String[] { FRIEND_ID, BN_TRANS }; Cursor friendCursor2 = database.query(TABLE_NAME, allColumns2, null, null, null, null, null); if (friendCursor2 != null) { friendCursor2.moveToFirst(); } //return friendCursor; if(!friendCursor2.isAfterLast()) { do { String name = friendCursor2.getString(1); trans1.add(name); } while (friendCursor2.moveToNext()); } friendCursor2.close(); String [] bntrans1= new String[trans1.size()]; bntrans1 = trans1.toArray(bntrans1); ListAdapter adapter = new ArrayAdapter<String>( getApplicationContext(), R.layout.alert_row, seleted_route) { ViewHolder holder; Drawable icon; class ViewHolder { ImageView icon; TextView title; TextView title2; } public View getView(int position, View convertView, ViewGroup parent) { final LayoutInflater inflater = (LayoutInflater) getApplicationContext() .getSystemService( Context.LAYOUT_INFLATER_SERVICE); if (convertView == null) { convertView = inflater.inflate( R.layout.alert_row, null); holder = new ViewHolder(); //holder.icon = (ImageView) convertView // .findViewById(R.id.icon4); holder.title = (TextView) convertView .findViewById(R.id.title4); holder.title2 = (TextView) convertView .findViewById(R.id.title2); convertView.setTag(holder); } else { // view already defined, retrieve view holder holder = (ViewHolder) convertView.getTag(); } Drawable drawable = getResources().getDrawable(R.drawable.iqra1); //this is an image from the drawables folder holder.title.setText(seleted_route[position]); holder.title2.setText(seleted_route[position]); //holder.icon.setImageDrawable(drawable); return convertView; } }; 

In the second way, I can fill in two columns in two text representations on the same line. But what I want is that the corresponding lines with the same line identifier should be filled in one line of the list using verse I. The identifier is identical in lines, maybe 5, 10 or twenty lines of the same identifier. Whenever the same identifier they are one line, When Identification changes the beginning of a new line.

0
source share

Source: https://habr.com/ru/post/910547/


All Articles