我們通過從共享首選項中獲取值來創建列表視圖。工作流程將如此。在行視圖的末尾添加動態生成列表的靜態按鈕
- 客戶登錄到應用程序,並點擊收藏夾標籤。對於第一次模式視圖將出現切換開關。
- 客戶可以選擇切換開關來添加他們最喜歡的選項並保存。
- 在下次登錄時,當客戶點擊收藏夾選項卡時,列表將顯示出他之前選擇的選項。
- 現在我們想要在按鈕上添加一個靜態按鈕(用於編輯),點擊按鈕後將顯示帶有切換開關頁面的模態視圖。
但是,當我試圖在我的XML文件中添加按鈕時,我正在每行中獲取按鈕。您在這方面的幫助將非常可觀。
佈局(XML文件)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="2dp"
android:layout_marginTop="15dp"
>
<ImageView
android:id="@+id/logo"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
>
</ImageView>
<TextView
android:id="@+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@+id/label"
android:textSize="14dp" >
</TextView>
</LinearLayout>
dummy.java
import kvbank.kvb_epassbook.util.MobileArrayAdapter;
import android.app.ListActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import android.view.View;
import android.widget.ListView;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.KeyEvent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import java.util.ArrayList;
public class dummy extends ListActivity {
//String[] MOBILE_OS = new String[15] ;
ArrayList<String> MOBILE_OS = new ArrayList<String>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final SharedPreferences sp = PreferenceManager
.getDefaultSharedPreferences(this);
int count1 = sp.getInt("count", -1);
String cc = String.valueOf(count1);
System.out.println(cc);
if((count1 == 0) || (count1==-1)){
Intent i = new Intent(this, favorites.class);
startActivity(i);
Toast.makeText(getApplicationContext(), "No favorites Set!!! =)",
Toast.LENGTH_LONG).show();
}
else
{
SharedPreferences.Editor editor = sp.edit();
boolean ad = sp.getBoolean("accdet", false);
if(ad == true){
MOBILE_OS.add("AccountDetails") ;
}
boolean as =sp.getBoolean("accsumm", false);
if(as == true){
MOBILE_OS.add("AccountSummary") ;
}
boolean ast =sp.getBoolean("accstmt", false);
if(ast == true){
MOBILE_OS.add("AccountStatement") ;
}
boolean crl =sp.getBoolean("CRL", false);
if(crl == true){
MOBILE_OS.add("Cash Remitance Limit") ;
}
boolean cse =sp.getBoolean("CSE", false);
if(cse == true){
MOBILE_OS.add("Cheque Status Enquiry") ;
}
boolean ic =sp.getBoolean("inwchq", false);
if(ic == true){
MOBILE_OS.add("Inward Cheque") ;
}
boolean uca =sp.getBoolean("Unclramt", false);
if(uca == true){
MOBILE_OS.add("uncleared Amount") ;
}
boolean dt =sp.getBoolean("depdet", false);
if(dt == true)
{
MOBILE_OS.add("Deposit Details") ;
}
setListAdapter(new MobileArrayAdapter(this, MOBILE_OS));
}
}
protected void onListItemClick(ListView l, View v, int position, long id) {
//get selected items
String selectedValue = (String) getListAdapter().getItem(position);
Toast.makeText(this, selectedValue, Toast.LENGTH_SHORT).show();
}
}
MobileArrayAdapter
import java.util.ArrayList;
import kvbank.kvb_ebook.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
public class MobileArrayAdapter extends ArrayAdapter<String> {
private final Context context;
private final ArrayList<String> values;
public MobileArrayAdapter(Context context, ArrayList<String> mOBILE_OS) {
super(context, R.layout.list_mobile, mOBILE_OS);
this.context = context;
this.values = mOBILE_OS;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.list_mobile, parent, false);
TextView textView = (TextView) rowView.findViewById(R.id.label);
ImageView imageView = (ImageView) rowView.findViewById(R.id.logo);
textView.setText(values.get(position));
// Change icon based on name
String s = values.get(position);
if (s.equals("AccountDetails")) {
imageView.setImageResource(R.drawable.acctinf);
} else if (s.equals("AccountStatement")) {
imageView.setImageResource(R.drawable.acctstat);
} else if (s.equals("AccountSummary")) {
imageView.setImageResource(R.drawable.acctsum);
} else if(s.equals("Cash Remitance Limit")){
imageView.setImageResource(R.drawable.cashret1);
} else if(s.equals("Cheque Status Enquiry")){
imageView.setImageResource(R.drawable.chqbkenq);
} else if(s.equals("Inward Cheque")){
imageView.setImageResource(R.drawable.inwchq);
} else if(s.equals("uncleared Amount")){
imageView.setImageResource(R.drawable.uncl1);
} else if(s.equals("Deposit Details")){
imageView.setImageResource(R.drawable.tddet);
} else if(s.equals("Deposit Summary")){
imageView.setImageResource(R.drawable.tdsum);
} else if(s.equals("Deposit Statement")){
imageView.setImageResource(R.drawable.dep_stmt);
} else if(s.equals("Loan Details")){
imageView.setImageResource(R.drawable.lndet);
} else if(s.equals("Loan Summary")){
imageView.setImageResource(R.drawable.lnsumm1);
} else if(s.equals("Loan Statement")){
imageView.setImageResource(R.drawable.lnsumm1);
} else if(s.equals("Alert Maintenance")){
imageView.setImageResource(R.drawable.alertreg);
} else if (s.equals("Forex Rates")){
imageView.setImageResource(R.drawable.forex1);
}
else if(s.equals("Cheque Book Request"))
{
imageView.setImageResource(R.drawable.chqreq) ;
}
return rowView;
}
}
?意思是低於名單? –
不在列表的最後。該列表將滾動,但按鈕應該是靜態的 –
分享您的活動佈局。 –