How would I get rid of "TextView" shown at the end of each item in the image 我如何摆脱图像中每个项目末尾显示的“ TextView”?在任何地方都找不到“ TextView”。我没有在任何地方提供“ TextView”,并且我从中获得代码的网站在它们中没有输出。 我使用了来自其他网站的代码,因此声明看起来不会相互关联。
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ScreenOne">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:textSize="20sp"/>
<Button
android:id="@+id/findSelected"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Next>" />
<ListView
android:id="@+id/listView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
public class ScreenOne extends AppCompatActivity {
MyCustomAdapter dataAdapter = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_screen_one);
displayListView();
checkButtonClick();
}
private void displayListView() {
//Array list of countries
ArrayList<Country> countryList = new ArrayList<Country>();
Country country = new Country("PC (Laptop/desktop)",false);
countryList.add(country);
country = new Country("Mobile phone",true);
countryList.add(country);
country = new Country("Electricals",false);
countryList.add(country);
country = new Country("Printer",true);
countryList.add(country);
country = new Country("Kettle",true);
countryList.add(country);
country = new Country("Microwave",false);
countryList.add(country);
country = new Country("Fridge",false);
countryList.add(country);
//create an ArrayAdaptar from the String Array
dataAdapter = new MyCustomAdapter(this,
R.layout.country_info, countryList);
ListView listView = (ListView) findViewById(R.id.listView1);
// Assign adapter to ListView
listView.setAdapter((ListAdapter) dataAdapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener(){
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// When clicked, show a toast with the TextView text
Country country = (Country) parent.getItemAtPosition(position);
Toast.makeText(getApplicationContext(),
"Clicked on Row: " + country.getName(),
Toast.LENGTH_LONG).show();
}
});
}
private class MyCustomAdapter extends ArrayAdapter<Country> {
private ArrayList<Country> countryList;
public MyCustomAdapter(ScreenOne context, int textViewResourceId,
ArrayList<Country> countryList) {
super(context, textViewResourceId, countryList);
this.countryList = new ArrayList<Country>();
this.countryList.addAll(countryList);
}
private class ViewHolder {
TextView code;
CheckBox name;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
Log.v("ConvertView", String.valueOf(position));
if (convertView == null) {
LayoutInflater vi = (LayoutInflater)getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
convertView = vi.inflate(R.layout.country_info, null);
holder = new ViewHolder();
holder.code = (TextView) convertView.findViewById(R.id.code);
holder.name = (CheckBox)
convertView.findViewById(R.id.checkBox1);
convertView.setTag(holder);
holder.name.setOnClickListener( new View.OnClickListener() {
public void onClick(View v) {
CheckBox cb = (CheckBox) v ;
Country country = (Country) cb.getTag();
Toast.makeText(getApplicationContext(),
"Clicked on Checkbox: " + cb.getText() +
" is " + cb.isChecked(),
Toast.LENGTH_LONG).show();
country.setSelected(cb.isChecked());
}
});
}
else {
holder = (ViewHolder) convertView.getTag();
}
Country country = countryList.get(position);
holder.name.setText(country.getName());
holder.name.setChecked(country.isSelected());
holder.name.setTag(country);
return convertView;
}
}
private void checkButtonClick() {
Button myButton = (Button) findViewById(R.id.findSelected);
myButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(ScreenOne.this,ScreenTwo.class));
}
});
}
}
答案 0 :(得分:0)
在返回convertView之前,添加以下内容:
UPDATE myTable SET name=REPLACE(name, "�", "ñ");
建议:我了解您只是从其他解决方案中借用代码,但不要害怕对其进行个性化设置。不用保留变量 country ,而是将其重命名为适合您的项目的名称(例如 appliance )。如果您在android studio中选择了变量,然后右键单击它,选择refactor-> rename并给它一个新名称,它将在所有使用的地方更改该变量的名称,而您不必担心忘记一些东西。