-
-
Save udacityandroid/042a390d4414f32a5558 to your computer and use it in GitHub Desktop.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:orientation="vertical" | |
android:paddingBottom="@dimen/activity_vertical_margin" | |
android:paddingLeft="@dimen/activity_horizontal_margin" | |
android:paddingRight="@dimen/activity_horizontal_margin" | |
android:paddingTop="@dimen/activity_vertical_margin" | |
tools:context=".MainActivity"> | |
<TextView | |
android:id="@+id/menu_item_1" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="Mango sorbet" | |
android:textAppearance="?android:textAppearanceMedium" /> | |
<TextView | |
android:id="@+id/menu_item_2" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_marginTop="8dp" | |
android:text="Blueberry pie" | |
android:textAppearance="?android:textAppearanceMedium" | |
android:textSize="18sp" /> | |
<TextView | |
android:id="@+id/menu_item_3" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_marginTop="8dp" | |
android:text="Chocolate lava cake" | |
android:textAppearance="?android:textAppearanceMedium" | |
android:textSize="18sp" /> | |
<Button | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_marginTop="8dp" | |
android:onClick="printToLogs" | |
android:text="Print menu to logs" /> | |
</LinearLayout> |
package com.example.android.menu; | |
import android.os.Bundle; | |
import android.support.v7.app.AppCompatActivity; | |
import android.view.View; | |
public class MainActivity extends AppCompatActivity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
} | |
public void printToLogs(View view) { | |
// Find first menu item TextView and print the text to the logs | |
// Find second menu item TextView and print the text to the logs | |
// Find third menu item TextView and print the text to the logs | |
} | |
} |
@shubhams612 ,i m getting the same problem ,have u got it solved ?
I guess dimen.xml file if not there in resource/values/.
You can replace the error text with "16dp" temporarily
or you can create new dimen.xml file in resource/values/
public void printToLogs(View View){
TextView menu1 = (TextView) findViewById(R.id.menu_item_1);
String ahmed = (String) menu1.getText();
Log.i("MainActivity", ahmed);
TextView menu2 = (TextView) findViewById(R.id.menu_item_2);
ahmed = (String) menu2.getText();
Log.i("MainActivity", ahmed);
TextView menu3 = (TextView) findViewById(R.id.menu_item_3);
ahmed = (String) menu3.getText();
Log.i("MainActivity", ahmed);
}
package com.example.menu;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
Button button;
TextView menu_item_1, menu_item_2, menu_item_3;
@OverRide
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = findViewById(R.id.menu_Btn);
menu_item_1 = findViewById(R.id.menu_item_1);
button.setOnClickListener(v -> {
printToLogs(menu_item_1);
});
}
public void printToLogs(View view) {
// Find first menu item TextView and print the text to the logs
Log.i("EnterpriseActivity.java", "Captin's Log, Stardate 43125.8." + "Mango sorbet");
// Find second menu item TextView and print the text to the logs
Log.i("EnterpriseActivity.java", "Captin's Log, Stardate 43125.8." + "Blueberry Pie");
// Find third menu item TextView and print the text to the logs
Log.i("EnterpriseActivity.java", "Captin's Log, Stardate 43125.8." + "Choolate lava cack");
}
}
why am i getting this error
