gpt4 book ai didi

android - ListView 仅显示 10 个项目

转载 作者:搜寻专家 更新时间:2023-11-01 09:25:05 25 4
gpt4 key购买 nike

我想实现一种方法,允许我使用来自 strings.xml 的 2 个不同的字符串数组实现 ListView 。我的代码有效,但我的手机只能显示前 10 个项目。我的问题在哪里?如果我尝试在虚拟设备上运行代码,它会正常工作。

这是我的代码,只有一个 TextView 。 (这个只显示前 10 项)

Button btt_backHome;
ListView lV_titoli;
EditText eT_search;
private ArrayAdapter<CharSequence> adapter , adapter_testi;
ImageView img_titoli;
List<RowData> rowData;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_titoli);

img_titoli = (ImageView) findViewById(R.id.img_titoli); // Create an icon
Picasso.get().load(R.drawable.sfondo).resize(2048, 1356).centerInside().into(img_titoli);

btt_backHome = (Button) findViewById(R.id.btt_backHome);
lV_titoli = (ListView) findViewById(R.id.lV_titoli);
eT_search = (EditText) findViewById(R.id.eT_search);

//serve per nascondere la tastiera
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);


adapter = ArrayAdapter.createFromResource(this, R.array.titoli, android.R.layout.simple_list_item_1);
lV_titoli.setAdapter(adapter);
adapter.getFilter().filter("");

final Intent refresh = new Intent(this, activity_titoli.class);
final Intent to_Home = new Intent (this , Activity_Main.class);
final Intent to_Canzone_from_titoli = new Intent (this , activity_canzone.class);

eT_search.addTextChangedListener(new TextWatcher() {

@Override
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub

}

@Override
public void beforeTextChanged(CharSequence arg0, int arg1,
int arg2, int arg3) {
// TODO Auto-generated method stub
}

@Override
public void onTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
(activity_titoli.this).adapter.getFilter().filter(arg0);
}
});

btt_backHome.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(to_Home);
}
});

lV_titoli.setOnItemClickListener(new AdapterView.OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

Resources res = getResources();
List<String> list = Arrays.asList(res.getStringArray(R.array.titoli));

to_Canzone_from_titoli.putExtra("riga", list.indexOf(adapter.getItem(i)));
startActivity(to_Canzone_from_titoli);

}
});
}

这是我的 xml 代码:

<ImageView
android:id="@+id/img_titoli"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="1"
android:scaleType="fitXY"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/btt_backHome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginTop="8dp"
android:text="indietro"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<android.support.constraint.Guideline
android:id="@+id/guideline2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_begin="20dp" />

<EditText
android:id="@+id/eT_search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="64dp"
android:ems="10"
android:hint="Ricerca..."
android:inputType="textPersonName"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="128dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<ListView
android:id="@+id/lV_titoli"
android:layout_width="match_parent"
android:layout_height="500dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</LinearLayout>
</ScrollView>

最佳答案

<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="128dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<ListView
android:id="@+id/lV_titoli"
android:layout_width="match_parent"
android:layout_height="500dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</LinearLayout>
</ScrollView>

这就是问题所在。您有一个嵌套在 ScrollView 中的 ListView 。你不需要这样做,因为 ListView 本身会滚动。试试这个代替整个事情:

<ListView
android:id="@+id/lV_titoli"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="128dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">


</ListView>

关于android - ListView 仅显示 10 个项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51313482/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com