Notice
Recent Posts
Recent Comments
Link
관리 메뉴

설.현.아빠

[ListView] 사진과 marquee tag를 사용한 ListView Source 본문

안드로이드/List

[ListView] 사진과 marquee tag를 사용한 ListView Source

설.현.아빠 2011. 2. 11. 10:47




 

<?xml version="1.0" encoding="utf-8"?>

 

<!-- main.xml -->


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
 <LinearLayout
  android:orientation="horizontal"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:layout_weight="7">
  <TableLayout
   xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:stretchColumns="1">
   <TableRow>
    <TextView
     android:layout_column="1"
     android:text="새로고침"
     android:padding="3dip"
     />
    <TextView
     android:text="83개의 목록을 가져왔습니다."
     android:gravity="right"
     android:padding="3dip"
     />
   </TableRow>
  </TableLayout>
 </LinearLayout>
 
 <LinearLayout
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:layout_weight="1">
  <ListView
   android:id="@+id/android:list"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   />
  <TextView
   android:id="@+id/android:empty"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:text="@string/main_no_items"
   />
 </LinearLayout>

 <LinearLayout
  android:orientation="horizontal"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:layout_weight="7">
  <TableLayout
   xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:stretchColumns="1">
   <TableRow>
    <TextView
     android:id="@+id/btn01"
     android:layout_column="1"
     android:text="인원별"
     android:padding="5dip" />  
    <TextView

     android:id="@+id/btn02"
     android:text="장소별"
     android:padding="5dip" />
    <TextView
     android:text="평가순"
     android:padding="5dip" />
    <TextView
     android:text="테마별"
     android:padding="5dip" />
     <TextView
     android:text="무작위"
     android:padding="5dip" />
     <TextView
     android:text="내위치"
     android:padding="5dip" />
   </TableRow>
  </TableLayout>
 </LinearLayout>
</LinearLayout>

 

<?xml version="1.0" encoding="utf-8"?>

 

<!-- row.xml -->


<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content">
  <ImageView
   android:id="@+id/icon"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:layout_marginRight="6dip"
   android:src="@drawable/icon"
   />
  <LinearLayout
   android:orientation="vertical"
   android:layout_width="0dip"
   android:layout_height="fill_parent"
   android:layout_weight="1"
   >
   <TextView
    android:id="@+id/toptext"
    android:layout_width="fill_parent"
    android:layout_height="0dip"
    android:layout_weight="1"
    android:gravity="center_vertical"
    />
   <TextView
    android:id="@+id/bottomtext"
    android:layout_width="fill_parent"
    android:layout_height="0dip"
    android:layout_weight="1"
    android:singleLine="true"
    android:ellipsize="marquee"
    />
   </LinearLayout>
</LinearLayout>

 

<?xml version="1.0" encoding="utf-8"?>

 

<!-- String.xml -->


<resources>
    <string name="hello">Hello World, AndroidList!</string>
    <string name="app_name">&amp;.&amp;함께가요~동행!</string>
    <string name="main_no_items">main_no_items</string>
</resources>


 <!--

여기서 중요한 것은 &.&함께가요~동행! 이란 Label String을 지정해 줄때 &를 바로 출력하지 못한다.

위와 같이 &amp; = &와 동일한 기능을 한다.

-->

 

// orderClass.java

 

package my.android.app;

public class orderClass {
 private String orderName;
 private String orderStatus;
 
 public String getOrderNamge() {
  return orderName;
 }
 
 public String getOrderStatus() {
  return orderStatus;
 }
 
 public void setOrderName(String orderName) {
  this.orderName = orderName;
 }
 
 public void setOrderStatus(String orderStatus) {
  this.orderStatus = orderStatus;
 }
}

 

// androidlist.java

 

package my.android.app;

 

import java.util.ArrayList;

import android.app.ListActivity;
import android.app.ProgressDialog;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

 

public class androidlist extends ListActivity {
    /** Called when the activity is first created. */
 private ProgressDialog m_ProgressDialog = null;
 private ArrayList<orderClass> m_orders=null;
 private OrderAdapter m_adapter;
 private Runnable viewOrders;
 String[] imsi = { "춘천맛집을찾아서...", "춘천맛집을찾아서...", "춘천맛집을찾아서...",
   "춘천맛집을찾아서...", "춘천맛집을찾아서...", "춘천맛집을찾아서...", "춘천맛집을찾아서...",
   "춘천맛집을찾아서...", "춘천맛집을찾아서...", "춘천맛집을찾아서...", "춘천맛집을찾아서...",
   "춘천맛집을찾아서...", "춘천맛집을찾아서...", "춘천맛집을찾아서...", "춘천맛집을찾아서...",
   "춘천맛집을찾아서...", "춘천맛집을찾아서...", "춘천맛집을찾아서...", "춘천맛집을찾아서...",
   "춘천맛집을찾아서...", "춘천맛집을찾아서...", "춘천맛집을찾아서...", "춘천맛집을찾아서...",
   "춘천맛집을찾아서...", "춘천맛집을찾아서...", "춘천맛집을찾아서...", "춘천맛집을찾아서...",
   "춘천맛집을찾아서...", "춘천맛집을찾아서...", "춘천맛집을찾아서..." }; 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        m_orders = new ArrayList<orderClass>();
        this.m_adapter = new OrderAdapter(this, R.layout.row, m_orders);
        setListAdapter(this.m_adapter);
        
        View btn01 = findViewById(R.id.btn01);
        btn01.setOnClickListener(new View.OnClickListener() {
   
   @Override
   public void onClick(View v) {
    // TODO Auto-generated method stub
    test1();
   }
  });
        
        View btn02 = findViewById(R.id.btn02);
        btn02.setOnClickListener(new View.OnClickListener() {
   
   @Override
   public void onClick(View v) {
    // TODO Auto-generated method stub
    test2();
   }
  });
        
        viewOrders = new Runnable() {
         public void run() {
          getOrders();
         }
        };
        
        Thread thread = new Thread(null, viewOrders, "MagentoBackground");
        thread.start();
        m_ProgressDialog = ProgressDialog.show(androidlist.this, "Please wait...", "Retrieving data...", true);
    }
    
    private void test1() {
     imsi[0] = "인원많은순으로 변경중...";
     getOrders();
     Thread thread = new Thread(null, viewOrders, "MagentoBackground");
     thread.start();
     m_ProgressDialog = ProgressDialog.show(androidlist.this, "인원많은순으로 변경중...", "통신중이야~",true);
    }
    
    private void test2() {
     imsi[0] = "장소많은순으로 변경중...";
     getOrders();
     Thread thread = new Thread(null, viewOrders, "MagentoBackground");
     thread.start();
     m_ProgressDialog = ProgressDialog.show(androidlist.this, "장소많은순으로 변경중...", "다 되간다. 기다려~",true);
    }
    
    private Runnable returnRes = new Runnable() {
     public void run() {
      if(m_orders != null && m_orders.size() > 0) {
       m_adapter.notifyDataSetChanged();
       for(int i=0;i<m_orders.size();i++)
        m_adapter.add(m_orders.get(i));
      }
      m_ProgressDialog.dismiss();
      m_adapter.notifyDataSetChanged();
     }
    };
    
 private void getOrders() {

  try {
   m_orders = new ArrayList<orderClass>();
   orderClass o1;
   for (int i = 0; i < imsi.length; i++) {
    o1 = new orderClass();
    if (i % 2 == 0) {
     o1.setOrderName("음식");
    } else {
     o1.setOrderName("여행 ");
    }
    o1.setOrderStatus(i + " : " + imsi[i]);
    m_orders.add(o1);
   }

   Thread.sleep(5000);
   Log.i("ARRAY", "" + m_orders.size());
  } catch (Exception e) {
   Log.e("BACKGROUND_PROC", e.getMessage());
  }
  runOnUiThread(returnRes);
 }

 private class OrderAdapter extends ArrayAdapter<orderClass> {

  private ArrayList<orderClass> items;

  public OrderAdapter(Context context, int textViewResourceId,
    ArrayList<orderClass> _items) {
   super(context, textViewResourceId, _items);
   this.items = _items;
  }

  public View getView(int position, View convertView, ViewGroup parent) {
   View view = convertView;
   if (view == null) {
    LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    view = vi.inflate(R.layout.row, null);
   }
   orderClass orderclass = items.get(position);
   if (orderclass != null) {
    TextView tt = (TextView) view.findViewById(R.id.toptext);
    TextView bt = (TextView) view.findViewById(R.id.bottomtext);
    if (tt != null) {
     tt.setText("★★★★☆ " + orderclass.getOrderName());
    }
    if (bt != null) {
     bt.setText("[" + orderclass.getOrderName() + "]"
       + orderclass.getOrderStatus());
    }
   }
   return view;
  }
 }
}

 


Comments