我创建了一个弹出窗口,可用于在应用程序中显示重要消息。此代码使用PopActivity编写。
这是我的代码:
public class PopActivity extends Activity {
private WorkOutClass the_workout_class = new WorkOutClass();
private TextView repTextField, setsTextField;
private Button den_knappen;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pop);
repTextField = (TextView) findViewById(R.id.repetitionID);
setsTextField = (TextView) findViewById(R.id.setsID);
den_knappen = (Button) findViewById(R.id.buttonID);
repTextField.setText("Reps : " + String.valueOf(the_workout_class.getReps()));
setsTextField.setText("Sets: " +String.valueOf(the_workout_class.getSets()));
DisplayMetrics thePopUpWindow = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(thePopUpWindow);
int width = thePopUpWindow.widthPixels;
int height = thePopUpWindow.heightPixels;
getWindow().setLayout((int)(width*.8), (int)(height*.7));
WindowManager.LayoutParams params = getWindow().getAttributes();
params.gravity = Gravity.CENTER;
params.x = 0;
params.y = 20;
getWindow().setAttributes(params);
den_knappen.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
the_workout_class.increaseReps();
repTextField.setText("Reps : " + String.valueOf(the_workout_class.getReps()));
setsTextField.setText("Sets: " +String.valueOf(the_workout_class.getSets()));
}
});
}}
我的问题是:如果我想在应用程序中其他提供不同消息的地方使用相同类型的弹出窗口,有没有办法我可以复制它来使用它?还是我需要创建新文件,例如PopActivity2,PopActivity3等?
感谢您的回答。
答案 0 :(得分:1)
对我来说,您真正需要的是Dialog
。您可以为对话框创建自己的布局和文本,然后在需要的地方使用它。这些链接可以帮助您:
https://developer.android.com/guide/topics/ui/dialogs
答案 1 :(得分:0)
启动活动时,您可以通过Intent传递数据,例如
$scope.addUserRow = function () {
var l = $scope.customUserResponse.length;
if(l==0)
{
l = $scope.customUserQuestion.length;
}
var quest = {Question_Text__c:"", Response_Value__c:"", Status__c:"", Comments__c:"",
Is_Global__c:"false", Order__c:l};
$scope.enabledEditResponse[l] = true;
$scope.customUserResponse.push(quest);
//var element = document.getElementByClass("deleteButton");
//element.classList.remove("ng-hide");
//angular.element(document.querySelector("#deleteButton")).removeClass("ng-hide");
//$scope.showDeleteBtn = true;
//$scope.$apply();
};
,并将其用作您需要的消息。您可以根据需要传递更多数据。最好的办法是为名称(“ first”)定义一个具有更好名称的常量,并将其用于两个Activity;-)