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

안녕하세요. 레이아웃 질문좀 하겠습니다

0 추천
public class BookmarkListActivity extends Activity implements OnClickListener {

 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  setContentView(R.layout.query);
  LinearLayout layout = (LinearLayout) findViewById(R.id.sites);

  try {
   // DBManager 객체 생성(DB 존재 않으면 생성)
   DBManager dbmgr = new DBManager(this);

   // DB 연결
   SQLiteDatabase sdb = dbmgr.getReadableDatabase();
   // SQL문 실행 결과를 cursor 객체로 받음
   Cursor cursor = sdb.rawQuery("select wid, wname, waddress, remark, hits from websites", null);

   int i = 0;

   while (cursor.moveToNext()) {
    String wid = cursor.getString(0);
    String wname = cursor.getString(1);
    String waddress = cursor.getString(2);
    String remark = cursor.getString(3);
    String hits = cursor.getString(4);

    TextView tv_list = new TextView(this);

    tv_list.append(wid);
    tv_list.append(wname);
    tv_list.append(waddress);
    tv_list.append(remark);
    tv_list.append(hits);
    
    layout.addView(tv_list);
    tv_list.setId(i);
    tv_list.setOnClickListener(this);
    tv_list.setTag(wid);

    i++;
   }

   if (i == 0) {
    TextView tv_desc = new TextView(this);
    tv_desc.append("등록된 사이트가 없습니다!");
    layout.addView(tv_desc);
   }

   cursor.close();
   dbmgr.close();
  } catch (SQLiteException e) {
   TextView tv_err = new TextView(this);
   // tv_desc.append("등록된 사이트가 없습니다!");
   tv_err.append(e.getMessage());
   layout.addView(tv_err);
  }
 }

 // 사이트이름이 클릭되었을 때
 public void onClick(View v) {
  Intent it = new Intent();
  // 현재 클래스에서 호출할 클래스 지정
  it = new Intent(this, BookmarkDetailActivity.class);
  // 입력한 값을 저장
  it.putExtra("it_name", (String) v.getTag());
  String str_name = it.getStringExtra("it_name");
  try{
   //DB객체 생성
   DBManager dbmgr = new DBManager(this);
   SQLiteDatabase sdb = dbmgr.getReadableDatabase();
   //클릭수 증가
   sdb.execSQL("update websites set hits=hits+1 where wid='"+ str_name + "' ");
   //객체 닫음
   dbmgr.close();
  }catch(SQLiteException e){
   //DB접속 또는 조회 시 에러 발생 할 때(생략)
  } 
  
  // 인텐트에서 지정한 액티비티 실행
  startActivity(it);
  // 현재 액티비티 종료
  finish();
 }
}

 

 

사진에서 '번호 이름 주소 설명 클릭수' 는 레이아웃에서 텍스트뷰로 weight = 1씩 해서 정렬했는데요.

 

그아래 사이트 정보는 SQLite에서 가져와서 리니어레이아웃에 그냥 뿌리는 방식으로 되어있어서 정렬이안되어있는데

 

번호      이름      주소      설명      클릭수

   1       네이..   http:/....  대한....       22

   2       구글     http:/....  Bes....        10

 

이런식으로 정렬해서 넘어가는부분은 ...으로 표시되게 하고싶은데, 방법이 없을까요??

 

안드로이드 초짜입니다. 죄송합니다만 설명은 너무 어렵지 않게 부탁드리겠습니다! ㅠ

 

khdad1 (300 포인트) 님이 2014년 6월 13일 질문
khdad1님이 2014년 6월 13일 수정
작성자입니다. 글자수 제한때문에 레이아웃 소스는 댓글에 달게요 ㅠ

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
     >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="번호"
            android:textSize="15sp"
            android:gravity="center_horizontal"
            />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="이름"
            android:textSize="15sp"
            android:gravity="center_horizontal"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="주소"
            android:textSize="15sp"
            android:gravity="center_horizontal"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="설명"
            android:textSize="15sp"
            android:gravity="center_horizontal"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="클릭수"
            android:textSize="15sp"
            android:gravity="center_horizontal"/>
    </LinearLayout>
    
    <!-- 사이트 조회 영역 -->
    <LinearLayout
        android:id="@+id/sites"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1">
    </LinearLayout>
    
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="※ 클릭해서 소스보기"
            android:textSize="15sp"
            android:gravity="center_horizontal"/>
        
    </LinearLayout>

</LinearLayout>

1개의 답변

+1 추천
 
채택된 답변
사이트조회영역 부분을 ListView로 바꾸시고 커스텀리스트뷰 사용해서 각각 데이터 입력하시면 정렬해서 데이터만큼 뿌릴수있어용^^
같이가자심해로 (1,150 포인트) 님이 2014년 6월 13일 답변
khdad1님이 2014년 6월 13일 채택됨
...