2011-04-04 70 views
0

我已經創建了字符串庫,但是android字符串庫不能從屏幕開始顯示。它顯示。任何解決方案安卓字符串庫不能從屏幕開始顯示

感謝客棧提前。

private Context cont; 
private String [] stringid=new String[]{"Index-Nifty","Positional calls","Intraday calls","InvestmentIdea","Optional calls","BTST-STBT calls"};  

public TabGallary(Context c) { 
    cont = c; 
} 

public int getCount(){ 
    return stringid.length; 
} 

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

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

public View getView(int position, View convertView, ViewGroup parent) {         
    TextView view = new TextView(cont);     

    //Fixing width & height for String to display 
    view.setLayoutParams(new Gallery.LayoutParams(125, 20)); 
    view.setSoundEffectsEnabled(true); 
    view.setText(stringid[position]);      
    view.setSingleLine(); 

    Intent intent = new Intent(); 
    startActivity(intent); 
    return view; 
} 

private void startActivity(Intent intent) { 
    // TODO Auto-generated method stub  
} 

回答

0

嘿..對於DAT u必須使用LayoutInflater

第一U創建一個XML文件 「demo.xml」

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/widget44" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical" 
android:gravity="center_horizontal"> 
    <TextView 
     android:id="@+id/txt1_gvi" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textColor="#051b4d" 
     android:gravity="center_horizontal" 
     android:textColorHighlight="#656565" 
     android:textSize="10sp"> 
    </TextView> 
</LinearLayout> 

現在烏爾適配器類應該像下面.. 這裏,而不是背景u必須通過活動.. 例如 代替public TabGallary(Context c) u必須public TabGallary(Activity a)

public Activity activity; 
    private static LayoutInflater inflater=null; 
    private String [] stringid=new String[]{"Index-Nifty","Positional calls","Intraday calls","InvestmentIdea","Optional calls","BTST-STBT calls"};  

    public TabGallary(Activity a) {  
     activity = a; 
     inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    } 

    public int getCount(){ 
     return stringid.length; 
    } 

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

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

    public View getView(int position, View convertView, ViewGroup parent) 
    {   
     View v;      
     if (convertView == null) 
     { 
      LayoutInflater li = getLayoutInflater(); 
      v = li.inflate(R.layout.demo, null); 
      TextView tv1 = (TextView)v.findViewById(R.id.txt1_gvi); 
      tv1.setText(stringid[position]); 
      v.setOnClickListener(new OnClickListener() 
      {      
        @Override 
        public void onClick(View v) 
        { 
        // Call intent or perform ur activity;     
        } 
      });  
     } 
     else 
     { 
     v= convertView; 
     }  

     return v; 
    } 
0

也許這是從第一顯示。這可能是因爲你已經爲Gallery設置了Layoutparams,你無法看到它。

+0

我剛剛刪除設置佈局? – Siten 2011-04-04 10:37:55

+0

它不工作..它只是重疊字符串,並從大約中旬開始。 – Siten 2011-04-04 10:40:23

+0

發佈您在主視圖中顯示圖庫的代碼部分 – pankajagarwal 2011-04-04 10:52:25