gpt4 book ai didi

java - 对话框未打开

转载 作者:太空宇宙 更新时间:2023-11-04 12:42:33 25 4
gpt4 key购买 nike

这是我的代码,应该打开项目的 ListView 。当单击某个项目时,它会打开相应的对话框。出现 ListView ,但根本不显示对话框。我在 logcat 中没有看到任何错误。请帮忙

import android.app.Dialog;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.playmaker.BudgetOh.R;
import com.playmaker.BudgetOh.manager.ExpenseManager;
import com.playmaker.BudgetOh.model.Expense;

import java.util.ArrayList;

public class ViewExpense extends ListActivity {
ExpenseManager expenseManager;
ArrayList<Expense> allExpenses;
ArrayList<String> allTitles;
ListView listView;
String titlePosition;
Dialog dialog;
Expense expense;


@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);

expenseManager = new ExpenseManager(this);
allTitles = new ArrayList<String>();
allExpenses = expenseManager.getAllExpenses();
listView = getListView();
listView.setBackgroundResource(R.color.viewBackground);
listView.setPadding(10, 20, 10, 15);
listView.setFooterDividersEnabled(true);
listView.setHeaderDividersEnabled(true);

// getting all the titles
for (Expense expense : allExpenses) {

allTitles.add(expense.getTitle());
}
listView.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, allTitles));

}

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {

super.onListItemClick(l, v, position, id);
titlePosition = allTitles.get(position);
expense = expenseManager.getExpense(titlePosition);

dialog = new Dialog(ViewExpense.this);
dialog.setContentView(R.layout.view_details);

TextView tvTime, tvTitle, tvAmount, tvCategory, tvComment;

tvTitle = (TextView) dialog.findViewById(R.id.tvViewTitle);
tvAmount = (TextView) dialog.findViewById(R.id.tvViewAmount);
tvCategory = (TextView) dialog.findViewById(R.id.tvViewCategory);
tvComment = (TextView) dialog.findViewById(R.id.tvViewComment);
tvTime = (TextView) dialog.findViewById(R.id.tvViewTime);

dialog.setTitle(expense.getTitle());
tvTitle.setText(expense.getTitle());
tvAmount.setText(expense.getAmount());
tvCategory.setText(expense.getCategory());
tvComment.setText(expense.getComment());
tvTime.setText("Created on " + expense.getDate() + " At "
+ expense.getTime());
dialog.show();

}

}

这是我的对话框布局

    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/Cream_Back"android:layout_width="match_parent"android:layout_height="match_parent"android:alpha="0.5"android:orientation="vertical"><LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">


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

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#E3CF57"
android:gravity="center"
android:text="Expense Title"
android:textSize="20sp"
android:textStyle="italic|bold" />

<TextView

android:id="@+id/tvViewTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="fill|center"
android:padding="20dp"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />

</LinearLayout>

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

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#E3CF57"
android:gravity="center"
android:text="Expense Amount"
android:textSize="20sp"
android:textStyle="italic|bold" />

<TextView

android:id="@+id/tvViewAmount"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="fill|center"
android:padding="20dp"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />

</LinearLayout>

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

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#E3CF57"
android:gravity="center"
android:text="Expense Category"
android:textSize="20sp"
android:textStyle="italic|bold" />

<TextView

android:id="@+id/tvViewCategory"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="fill|center"
android:padding="20dp"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />

</LinearLayout>

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

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#E3CF57"
android:gravity="center"
android:text="Time Recorded"
android:textSize="20sp"
android:textStyle="italic|bold" />

<TextView

android:id="@+id/tvViewTime"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="fill|center"
android:padding="20dp"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />

</LinearLayout>


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

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#E3CF57"
android:gravity="center"
android:text="Comments"
android:textSize="20sp"
android:textStyle="italic|bold" />

<TextView

android:id="@+id/tvViewComment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="fill|center"
android:padding="20dp"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />

</LinearLayout>


</LinearLayout>


</ScrollView>

最佳答案

无法发表评论,但我在您的 xml 中看到的是您没有正确关闭。您需要以 </Scrollview> 结束而不是</LinearLayout> 。还要确保 ScrollView 只托管一个 View ,因此只需用relativelayout 包装您的 LinearLayout-Views 即可。

尝试一下,看看是否打开对话框。

关于java - 对话框未打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36691271/

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