我试图将EditText从Activity1传递给Activity2.
Activity1代码:
public void openNextActivity()
{
Intent intent = new Intent("com.abc.xyz.ImageActivity");
EditText myEditText = (EditText)findViewById(R.id.myEditText);
int myEditTextId = myEditText.getId();
//For Test purpose ----- starts
// **Point1: next line of code works fine in this Activity1**
EditText myEditTextTest = (EditText)findViewById(myEditTextId);
//For Test purpose ----- ends
intent.putExtra("myEditText", myEditTextId);
startActivity(intent);
}
Run Code Online (Sandbox Code Playgroud)
Activity2代码:
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.comments_detail);
Bundle extras = getIntent().getExtras();
if(extras != null)
{
int myEditTextId = extras.getInt("myEditText");
// Point2: next line of code displays the correct Id
Log.d("tag","myEditTextId"+ myEditTextId); …Run Code Online (Sandbox Code Playgroud) android nullreferenceexception android-edittext android-view findviewbyid
我正在尝试根据用户实时指定的输入为我的Android应用程序实现动态按钮膨胀.单击时,按钮将其颜色从蓝色更改为红色.
负责此的代码如下:
LayoutInflater layoutsInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout linearLayout = (LinearLayout) findViewById(R.id.layout_for_buttons);
// Let's say that now we need only 3 buttons:
for (int i = 0; i < 3; i++) {
RelativeLayout buttonLayout = (RelativeLayout) layoutsInflater
.inflate(R.layout.button_layout, linearLayout, false);
Button button = (Button) buttonLayout.getChildAt(0);
button.setText("Button " + i);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View buttonView) {
Button button = (Button) buttonView;
GradientDrawable gradientDrawable = (GradientDrawable) button
.getBackground();
gradientDrawable.setColor(Color.RED);
gradientDrawable.invalidateSelf();
}
});
linearLayout.addView(buttonLayout);
linearLayout.invalidate();
}
Run Code Online (Sandbox Code Playgroud)
我追加按钮的布局很简单LinearLayout:
<LinearLayout …Run Code Online (Sandbox Code Playgroud) 我正在尝试DialogFragment按照本教程实现自定义.我的问题是我无法处理我的自定义视图的button.setOnClickListener事件.最奇怪的是我在.getText()按下按钮时没有问题,我找不到处理点击事件的方法.贝娄是我的代码:
SettingsDialogFragment.java
public class SettingsDialogFragment extends DialogFragment
{
@Override
public Dialog onCreateDialog(Bundle savedInstanceState)
{
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
// Get the layout inflater
LayoutInflater inflater = getActivity().getLayoutInflater();
final View view = inflater.inflate(R.layout.dialog_settings, null);
final Button colorButton =(Button) view.findViewById(R.id.colorButton_dialogSettings);
String s = colorButton.getText().toString();
System.out.println("its working "+s);
//NOT working
colorButton.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
System.out.println("OnClick");
}
});
// Inflate and set the layout for the dialog
// Pass null as the …Run Code Online (Sandbox Code Playgroud) 使用INVISIBLE选项隐藏小时为18,19,20,21的行.但它仍然留下了空洞的空白.有没有办法消除这个差距?
private void hideEveningHours() { // hiding evening rows
TableRow tr = (TableRow)findViewById(R.id.row18);
tr.setVisibility(View.INVISIBLE);
tr = (TableRow)findViewById(R.id.row19);
tr.setVisibility(View.INVISIBLE);
tr = (TableRow)findViewById(R.id.row20);
tr.setVisibility(View.INVISIBLE);
tr = (TableRow)findViewById(R.id.row21);
tr.setVisibility(View.INVISIBLE);
}
Run Code Online (Sandbox Code Playgroud)

java android android-layout android-view android-tablelayout
是)我有的
我在屏幕底部有一个浮动操作按钮.
我想要的是
我希望在活动恢复时为视图设置动画.动画会将FAB从0大小增加到填充大小,从中心开始并向所有方向增长,直到最终达到其完整大小.
这就像我们在一些Material Designed应用程序中看到的那样.
在Android Studio中,我看到了一个<View />节点,它具有Widget的所有属性.我很好奇,这个节点是什么,我怎么能用呢?
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/material_cyan_200"
/>
Run Code Online (Sandbox Code Playgroud) 在我的应用中,我有一个ViewPager。在其中一个页面中,我有另一个页面,ViewPager其中通过自定义ViewPager实现禁用了滑动手势:
public class NonSwipeableViewPager extends ViewPager {
public NonSwipeableViewPager(Context context) {
super(context);
}
public NonSwipeableViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
// Never allow swiping to switch between pages
return false;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
// Never allow swiping to switch between pages
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
这很好用;子ViewPager中的滑动手势被禁用。但是,除非从屏幕的最右端开始滑动,否则无法滑动父ViewPager。如何使子级ViewPager忽略所有触摸事件/将其传递给父级视图?
使用“ ConstraintLayout我有2个” TextView,当它们有足够的空间可以看到两者的内容时,我希望彼此相邻。但是,如果TextView A占用了大量空间并充满了整个屏幕宽度,则比我希望TextView B处于TextView A下而不是仍然在右侧但不可见(屏幕外)更是如此。
因此,使用下面的代码,我得到了TextView彼此相邻的2个代码。
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/text_view_a"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="8dp"
tools:text="a very long text ..." />
<TextView
android:id="@+id/text_view_b"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
app:layout_constraintLeft_toRightOf="@+id/text_view_a"
app:layout_constraintTop_toTopOf="parent"
tools:text="some text" />
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
如果没有足够的空间,我应该如何编辑此代码段,以使TextView B进入TextView A下?
在iOS中,当从nib文件(iOS等效于Android layout.xml文件)"膨胀"视图时,将调用视图的'awakeFromNib'方法.与测量不同,它只被称为一次.
在Android中是否有相当于awakeFromNib的内容?
我们需要能够将从布局加载的子视图分配给View子类上的成员变量.是的,我们可以在外部执行此操作,但我们正在努力让视图自行管理自己的成员.
我正在开发一个应用程序,用户可以在其中进行评论,并且正在向发布评论的用户推送通知。现在我有一个要求客户在通知中显示等级
我已经搜索一下,发现这个解决方案,定制通知,但现在我没有得到如何使用RatingBar。
android ×10
android-view ×10
android-xml ×1
findviewbyid ×1
java ×1
ratingbar ×1
remoteview ×1
xml ×1