2012-09-01 31 views
0

我有一個新聞應用程序,需要從url下載數據並將其顯示在listview中,但我想要第一行與其他人不同,因爲在那裏會顯示主要新聞可以說,我有這個適配器類來顯示所有行一樣的,我不能修改,以做我上面寫的,任何人可以幫助我Android listview第一行

這裏就是適配器類的

public class LazyAdapter extends BaseAdapter { 

private Activity activity; 
private ArrayList<HashMap<String, String>> data; 
private static LayoutInflater inflater=null; 
public ImageLoader imageLoader; 

public LazyAdapter(Activity a, ArrayList<HashMap<String, String>> d) { 
    activity = a; 
    data=d; 
    inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    imageLoader=new ImageLoader(activity.getApplicationContext()); 
} 



public int getCount() { 
    return data.size(); 
} 

public Object getItem(int position) { 
    return position; 
} 

public long getItemId(int position) { 
    return position; 
} 

public View getView(int position, View convertView, ViewGroup parent) { 

    View vi=convertView; 
    if(convertView==null){ 
     vi = inflater.inflate(R.layout.list_row, null); 
    } 

    TextView title = (TextView)vi.findViewById(R.id.title); // title 
    //TextView artist = (TextView)vi.findViewById(R.id.artist); // artist name 
    TextView author = (TextView)vi.findViewById(R.id.einfo1); // duration 
    TextView datetime = (TextView)vi.findViewById(R.id.einfo); 
    TextView story = (TextView)vi.findViewById(R.id.einfo2); 
    ImageView thumb_image=(ImageView)vi.findViewById(R.id.list_image); // thumb image 

    HashMap<String, String> n = new HashMap<String, String>(); 
    n = data.get(position); 


    // Setting all values in listview 
    title.setText(n.get(Home.TAG_TITLE)); 
    author.setText(n.get(Home.TAG_AUTHOR)); 
    datetime.setText(n.get(Home.TAG_DATETIME)); 
    story.setText(n.get(Home.TAG_STORY)); 
    thumb_image.setTag(n.get(Home.TAG_IMG)); 
    imageLoader.DisplayImage(n.get(Home.TAG_IMG), thumb_image); 
    return vi; 
} 
} 
+0

[Android的不同行在列表視圖中]可能的重複(http://stackoverflow.com/questions/12226465/android-different-rows-in-listview) – Luksprog

+0

你看到我的答案?它有幫助嗎? – AliSh

+1

它幫我,我投它:) –

回答

1

AliSh答案是一個很好的答案。它給你一個好看。但是,如果你想保持簡單,那就試試這個。 在getView()方法中,

if(position==0) 
{ 
    // do stuff for your headline 
} 
else 
{ 
    // do other stuff 
} 

Thx! 拉胡爾。