android listview 按钮样式,android-listview适配器中的按钮

博主分享了Android开发中ListView的问题。ListView数据来自服务器,包含文本、按钮和滚动索引。遇到按钮点击无反应、滚动索引显示异常等问题,给出了homempleb.xml、MainActivity.java、EfficientAdapter.java等代码示例,希望实现按钮和滚动索引正常工作。

任何可以解决我的问题..经过2天的奋斗,我终于获得了70%的产出. Exp:我有listview哪些数据来自服务器.在Listview里面有一些文本,按钮和滚动索引A,BC,D,E,F,G.

问题:按钮不起作用意味着当我单击它时…如果添加以下代码.

它看起来有些下面的图像:

在这里,我已经通过这种方式在XML中使用过—> com.woozzu.android.widget.IndexableListView

在这种情况下,按一下按钮无法正常工作滚动视图A,B,C的显示方式正确且工作正常.

状态1:-

homempleb.xml

android:id="@+id/scrollView1"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:layout_alignParentLeft="true"

android:background="#335552"

android:layout_below="@+id/relativeLayout4" >

android:id="@+id/homelistView"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_weight="1.04"

android:dividerHeight="0dip" />

?

MainActivity.java

public class MainActivity extends Activity implements

SearchView.OnQueryTextListener, SearchView.OnCloseListener {

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.homempleb);

Log.i("scan", " txtScanResult ");

ActionItem nextItem = new ActionItem();

final QuickAction quickAction = new QuickAction(this,

QuickAction.VERTICAL);

quickAction.addActionItem(nextItem);

quickAction.setOnDismissListener(new QuickAction.OnDismissListener() {

@Override

public void onDismiss() {

Toast.makeText(getApplicationContext(), "Dismissed",

Toast.LENGTH_SHORT).show();

}

});

// listView = (IndexableListView) findViewById(R.id.homelistView);

listView = (ListView) findViewById(R.id.homelistView);

listView.setTextFilterEnabled(true);

listView.setFastScrollEnabled(true);

listView.setFastScrollAlwaysVisible(true);

objectAdapter = new EfficientAdapter(this);

listView.setAdapter(objectAdapter);

}

EfficientAdapter.java

public class EfficientAdapter extends BaseAdapter implements SectionIndexer {

private String mSections = "#ABCDEFGHIJKLMNOPQRSTUVWXYZ";

ArrayList patientListArray;

private LayoutInflater mInflater;

private Context context;

protected ListView mListView;

private int positions;

ViewHolder holder;

public EfficientAdapter(Context context) {

mInflater = LayoutInflater.from(context);

this.context = context;

String patientListJson = CountriesList.jsonData;

JSONObject jssson;

try {

jssson = new JSONObject(patientListJson);

patientListJson = jssson.getString("PostPatientDetailResult");

} catch (JSONException e) {

e.printStackTrace();

}

Gson gson = new Gson();

JsonParser parser = new JsonParser();

JsonArray Jarray = parser.parse(patientListJson).getAsJsonArray();

patientListArray = new ArrayList();

for (JsonElement obj : Jarray) {

Patient patientList = gson.fromJson(obj, Patient.class);

patientListArray.add(patientList);

Log.i("patientList", patientListJson);

}

}

/**

* sorting the patientListArray data

*/

public void sortMyData() {

// sorting the patientListArray data

Collections.sort(patientListArray, new Comparator() {

@Override

public int compare(Object o1, Object o2) {

Patient p1 = (Patient) o1;

Patient p2 = (Patient) o2;

return p1.getName().compareToIgnoreCase(p2.getName());

}

});

}

public int getCount() {

return patientListArray.size();

}

public Object getItem(int position) {

return position;

}

public long getItemId(int position) {

return position;

}

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

this.positions = position;

if (convertView == null) {

convertView = mInflater.inflate(R.layout.homemplebrowview, parent,false);

holder = new ViewHolder();

holder.text1 = (TextView) convertView.findViewById(R.id.name);

holder.text2 = (TextView) convertView.findViewById(R.id.mrn);

holder.text3 = (TextView) convertView.findViewById(R.id.date);

holder.text4 = (TextView) convertView.findViewById(R.id.age);

holder.text5 = (TextView) convertView.findViewById(R.id.gender);

holder.text6 = (TextView) convertView.findViewById(R.id.wardno);

holder.text7 = (TextView) convertView.findViewById(R.id.roomno);

holder.text8 = (TextView) convertView.findViewById(R.id.bedno);

holder.btnList = (Button) convertView.findViewById(R.id.listbutton);

convertView.setTag(holder);

} else {

holder = (ViewHolder) convertView.getTag();

}

holder.text1.setText(Util.formatN2H(patientListArray.get(position)

.getName()));

holder.text2.setText(patientListArray.get(position).getMrnNumber());

holder.text3.setText(Util.formatN2H(patientListArray.get(position)

.getRoom()));

holder.text4.setText(Util.formatN2H(patientListArray.get(position)

.getAge()));

holder.text5.setText(Util.formatN2H(patientListArray.get(position)

.getGender()));

holder.text6.setText(Util.formatN2H(patientListArray.get(position)

.getWard()));

holder.text7.setText(Util.formatN2H(patientListArray.get(position)

.getRoom()));

holder.text8.setText(Util.formatN2H(patientListArray.get(position)

.getBed()));

// holder.btnList.setOnClickListener(new OnClickListener(test));

holder.btnList.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View v) {

Toast.makeText(context, "STAT", Toast.LENGTH_SHORT).show();

Intent next = new Intent(context, Home.class);

Log.i("next23", "next"+ next);

context.startActivity(next);

}

});

return convertView;

}

/*OnItemClickListener test = new OnItemClickListener() {

onItemClick(AdapterView> parent, View view, int position, long id){

((TextView)view.findViewById(R.id.yourTextViewId)).getText();

{

// Button btnList=(Button)v.findViewById(R.id.listbutton);

btnList.setOnClickListener(new OnClickListener(){

public void onClick(View v) {

Toast.makeText(context, "STAT", Toast.LENGTH_SHORT).show();

Intent next = new Intent(context, Home.class);

Log.i("next23", "next"+ next);

context.startActivity(next);

}

});

}

};

*/

static class ViewHolder {

public Button btnList;

public TextView text8;

public TextView text7;

public TextView text6;

public TextView text5;

public TextView text4;

public TextView text1;

public TextView text2;

public TextView text3;

}

@Override

public void notifyDataSetChanged() {

super.notifyDataSetChanged();

}

/*public void onItemClick(AdapterView> arg0, View v, final int position,

long arg3)

{

holder.btnList=(Button)v.findViewById(R.id.listbutton);

holder.btnList.setOnClickListener(new OnClickListener(){

public void onClick(View v) {

Toast.makeText(context, "STAT", Toast.LENGTH_SHORT).show();

Intent next = new Intent(context, Home.class);

Log.i("next23", "next"+ next);

context.startActivity(next);

}

});

}

*/

public int getPositionForSection(int section) {

// sorting the patientListArray data

sortMyData();

// If there is no item for current section, previous section will be

// selected

for (int i = section; i >= 0; i--) {

for (int j = 0; j < getCount(); j++) {

if (i == 0) {

// For numeric section

for (int k = 0; k <= 9; k++) {

if (StringMatcher.match(

String.valueOf(patientListArray.get(j)

.getName().charAt(0)),

String.valueOf(k)))

return j;

}

} else {

if (StringMatcher.match(

String.valueOf(patientListArray.get(j).getName()

.charAt(0)),

String.valueOf(mSections.charAt(i))))

return j;

}

}

}

return 0;

}

public int getSectionForPosition(int position) {

return 0;

}

public Object[] getSections() {

String[] sections = new String[mSections.length()];

for (int i = 0; i < mSections.length(); i++)

sections[i] = String.valueOf(mSections.charAt(i));

return sections;

}

}

状态2:-

在这种情况下,单击按钮可以正常工作,但滚动视图A,B,C也可以正常工作,但在侧面没有字母A,B,C,D,E,F,G …

如果我在homempleb.xml中添加了listview,那么它们都将无法正常工作,而不会像图像中那样显示字母索引.我希望按钮和滚动索引都像上面的图像一样工作..我在这个主题上不好.请帮我

?它以这种方式显示:

homempleb.xml

android:id="@+id/scrollView1"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:layout_alignParentLeft="true"

android:background="#335552"

android:layout_below="@+id/relativeLayout4" >

android:id="@+id/homelistView"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_weight="1.04"

android:dividerHeight="0dip" />

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值