我正在尝试开发一个Android应用程序。在我的应用中,我使用文本视图显示可用的BLE设备。但是我不想使用文本视图,而是要使用列表视图。我的代码需要进行哪些更改?我对如何使用列表视图和各种适配器感到困惑! 在这里,我提供了我的代码。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.nc.android.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello Bluetooth Scanners!" />
<Button
android:layout_width="100dp"
android:layout_height="50dp"
android:text="Scan"
android:id="@+id/StartScanButton"
android:layout_marginTop="40dp"/>
<Button
android:layout_width="wrap_content"
android:layout_height="50dp"
android:text="Stop Scanning"
android:id="@+id/StopScanButton"
android:layout_marginTop="40dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="100dp"
android:id="@+id/PeripheralTextView"
android:scrollbars="vertical"
android:maxLines="30" />
</RelativeLayout>
pip install opencv-python=3.3.0.9
答案 0 :(得分:0)
public ArrayList<model_> countries_lang = new ArrayList<model_>();
Adapter_search adapt;
在您的理由后
adapt = new Adapter_search(getActivity(), yourdata);
lv.setAdapter(adapt);
适配器类
public class Adapter_search extends BaseAdapter
Context c;
ArrayList<model_> players;
CustomFilter filter;
ArrayList<model_> filterList;
SessionManager session;
boolean isSet;
Adapter_search myAdapter;
private int selectedPosition = 0;
public Adapter_search(Context ctx, ArrayList<model_> players) {
// TODO Auto-generated constructor stub
this.c = ctx;
this.players = players;
this.filterList = players;
session = new SessionManager(c);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return players.size();
}
@Override
public Object getItem(int pos) {
// TODO Auto-generated method stub
return players.get(pos);
}
@Override
public long getItemId(int pos) {
// TODO Auto-generated method stub
/* int itemID;
// orig will be null only if we haven't filtered yet:
if (players == null)
{
itemID = pos;
}
else
{
itemID = players.indexOf(filterList.get(pos));
}
return itemID;*/
return players.indexOf(getItem(pos));
}
@Override
public View getView(final int pos, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
myAdapter = new Adapter_search(c, players);
LayoutInflater inflater = (LayoutInflater)
c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = inflater.inflate(R.layout.search_popup, null);
}
TextView nameTxt = (TextView) convertView.findViewById(R.id.textView_titllename);
final ImageView img = (ImageView) convertView.findViewById(R.id.tick);
//SET DATA TO THEM
nameTxt.setText(players.get(pos).getLangName());
convertView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
notifyDataSetChanged();
// Toast.makeText(c, players.get(pos).getLangName() + "+" +
players.get(pos).getid(), Toast.LENGTH_SHORT).show();
}
});
return convertView;
}
}
}