마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

리스트 뷰 질문입니다.

0 추천
package com.romen.CancerAdvice;

public class test extends Activity {
 
 
 public SQLiteDatabase db;
 public Cursor cursor;
 public SimpleCursorAdapter Adapter = null;
 public SimpleCursorAdapter AdapterStomach = null;
 private ListView lv;
 EditText inputSearch;
  ArrayAdapter<String> adapter;
  
 public static final String ROOT_DIR = "/data/data/com.romen.CancerAdvice/databases/";
 ProductDBHelper mHelper;

 public void setDB() {
  File folder = new File(ROOT_DIR);
  folder.mkdir();
  if (folder.exists()) {

  } else {
   folder.mkdirs();
   // Toast.makeText(this, "폴더생성", Toast.LENGTH_LONG).show();
  }

  
  AssetManager assetManager = getResources().getAssets();
  File outfile = new File(ROOT_DIR + "test.db"); 
  InputStream is = null;

  FileOutputStream fo = null;

  long filesize = 0;

  try {
     is = assetManager.open("test.db", AssetManager.ACCESS_BUFFER);
   filesize = is.available(); 
  
   if (outfile.length() <= 0) {
    byte[] tempdata = new byte[(int) filesize];
    is.read(tempdata);
    is.close();
    outfile.createNewFile();
    fo = new FileOutputStream(outfile);
    fo.write(tempdata);
    fo.close();
   } else {
    // Toast.makeText(this, "db있음", Toast.LENGTH_LONG).show();

   }
  } catch (IOException e) {
   Toast.makeText(this, "db이동실패", Toast.LENGTH_LONG).show();
  }
 }


 
 

 @Override
 public void onCreate(Bundle savedInstanceState) {

  setDB();
  super.onCreate(savedInstanceState);
  setContentView(R.layout.search_test);
  
   
  
//  ListView list = (ListView) findViewById(R.id.list);
  mHelper = new ProductDBHelper(this);

  db = mHelper.getWritableDatabase();
  cursor = db.rawQuery("SELECT * FROM test where title='관리'", null);
  startManagingCursor(cursor);
 
  AdapterStomach = new SimpleCursorAdapter(test.this,
    R.layout.mylist, cursor, new String[] { "content1" },
    new int[] { R.id.text1 });
  
  
 
//  list.setAdapter(AdapterStomach);
  
 

   inputSearch = (EditText) findViewById(R.id.inputSearch);
   

   
   //adapter = new ArrayAdapter<String>(this, R.layout.mylist, R.id.text1);
    lv = (ListView) findViewById(R.id.list);
    lv.setAdapter(AdapterStomach);
    lv.setTextFilterEnabled(true);
   
   inputSearch.addTextChangedListener(new TextWatcher() {
    
    @Override
    public void onTextChanged(CharSequence cs, int start, int before, int count) {
     // When user changed the Text
    }
    
    @Override
    public void beforeTextChanged(CharSequence arg0, int start, int before,
      int count) {
     // TODO Auto-generated method stub
     
    }
    
    @Override
    public void afterTextChanged(Editable s) {
     // TODO Auto-generated method stub
     String text = inputSearch.getText().toString().toLowerCase(Locale.getDefault());
     if(text.length() <= 0)
      return;
     
     db = mHelper.getWritableDatabase();
     cursor = db.rawQuery("SELECT * FROM test WHERE content1 LIKE '%"+ text +"%'", null);
     while(cursor.moveToNext()){
      android.util.Log.i("TEST"," cursor = " + cursor.getString(2));
     }
     lv.setAdapter(null);
     AdapterStomach = null;
     AdapterStomach = new SimpleCursorAdapter(test.this,
       R.layout.mylist, cursor, new String[] { "content1" },
       new int[] { R.id.text1  });
     lv.setAdapter(AdapterStomach);
     
     
    } 
   });

  
  lv.setOnItemClickListener(new OnItemClickListener() {
   @Override
   public void onItemClick(AdapterView<?> parent, View v,
     int position, long id) {
    cursor = db.rawQuery("SELECT * FROM test where title='관리'",
      null);
    startManagingCursor(cursor);
    Cursor c = (Cursor) AdapterStomach.getItem(position);
    String note = c.getString(2);

    AlertDialog.Builder bld = new AlertDialog.Builder(
      test.this);
    bld.setTitle(c.getString(1));
    bld.setMessage(note);
    bld.setIcon(R.drawable.ic_menu_edit);
    bld.setPositiveButton("닫기",
      new DialogInterface.OnClickListener() {

       @Override
       public void onClick(DialogInterface dialog,
         int which) {
        // TODO Auto-generated method stub

       }
      });
    bld.show();
    // Toast.makeText(getApplicationContext(), note,
    // Toast.LENGTH_LONG).show();
   }
  });

 }

 class ProductDBHelper extends SQLiteOpenHelper {

  public ProductDBHelper(Context context) {
   super(context, "test.db", null, 1);
   // TODO Auto-generated constructor stub
  }

  @Override
  public void onCreate(SQLiteDatabase db) {
   // TODO Auto-generated method stub

  }

  @Override
  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
   // TODO Auto-generated method stub

  }

 }

}

게임1 ||리스트  <------row 

게임2 ||리스트2  <-------row

 

이런식으로 한 로우에 2개의 칼럼이 오게 하고싶은데 어떻게 해야하나요?

 

 

익명사용자 님이 2014년 10월 21일 질문

1개의 답변

0 추천

R.layout.mylist 을

 

<LinerLayout>

<View />

<View />

</LinerLayout>

 

이런식으로 View 2개를 넣어서 하면되지 않을까요??? 

 

첫번째 view에 게임1 넣고 두번째 view에 리스트 넣고 

 

물론 아답터는 Base아답타러르 상속받아서 만들어야겠고요 

woojeong (1,140 포인트) 님이 2014년 10월 21일 답변
...