这是控制器
ArFragment arFragment;
private ModelRenderable bearRenderable, catRenderable, cowRenderable,
dogRenderable,elephantRenderable,ferretRenderable,hippopotamusRenderable, horseRenderable,koalaRenderable,lionRenderable,reindeerRenderable,wolverineRenderable;
ImageView bear, cat, cow, dog, elephant, ferret, hippopotamus, horse, koala, lion, reindeer, wolverine;
View arrayView[];
int selected = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
arFragment = (ArFragment) getSupportFragmentManager().findFragmentById(R.id.sceneform_ux_fragment);
//View
bear = (ImageView) findViewById(R.id.bear);
cat = (ImageView) findViewById(R.id.cat);
dog = (ImageView) findViewById(R.id.dog);
cow = (ImageView) findViewById(R.id.cow);
elephant = (ImageView) findViewById(R.id.elephant);
ferret = (ImageView) findViewById(R.id.ferret);
hippopotamus = (ImageView) findViewById(R.id.hippopotamus);
horse = (ImageView) findViewById(R.id.horse);
koala = (ImageView) findViewById(R.id.lion);
reindeer = (ImageView) findViewById(R.id.reindeer);
wolverine = (ImageView) findViewById(R.id.wolverine);
SetArrayView();
SetClickListener();
setupModel();
arFragment.setOnTapArPlaneListener(new BaseArFragment.OnTapArPlaneListener() {
@Override
public void onTapPlane(HitResult hitResult, Plane plane, MotionEvent motionEvent) {
//kill
if (selected == 1) {
Anchor anchor = hitResult.createAnchor();
AnchorNode anchorNode = new AnchorNode(anchor); anchorNode.setParent(arFragment.getArSceneView().getScene());
createModel(anchorNode, selected);
} }
}); }
private void setupModel() {
ModelRenderable.builder()
.setSource(this, R.raw.bear)
.build().thenAccept(renderable -> bearRenderable = renderable)
.exceptionally(
throwable -> {
Toast.makeText(this, "Unnable to load bear model", Toast.LENGTH_SHORT).show();
return null;
}
);
ModelRenderable.builder()
.setSource(this, R.raw.cat)
.build().thenAccept(renderable -> catRenderable = renderable)
.exceptionally(
throwable -> {
Toast.makeText(this, "Unnable to load cat model", Toast.LENGTH_SHORT).show();
return null;
}
);
ModelRenderable.builder()
.setSource(this, R.raw.cow)
.build().thenAccept(renderable -> cowRenderable = renderable)
.exceptionally(
throwable -> {
Toast.makeText(this, "Unnable to load cow model", Toast.LENGTH_SHORT).show();
return null;
}
);
ModelRenderable.builder()
.setSource(this, R.raw.dog)
.build().thenAccept(renderable -> dogRenderable = renderable)
.exceptionally(
throwable -> {
Toast.makeText(this, "Unnable to load dog model", Toast.LENGTH_SHORT).show();
return null;
}
);
ModelRenderable.builder()
.setSource(this, R.raw.elephant)
.build().thenAccept(renderable -> elephantRenderable = renderable)
.exceptionally(
throwable -> {
Toast.makeText(this, "Unnable to load elephant model", Toast.LENGTH_SHORT).show();
return null;
}
);
ModelRenderable.builder()
.setSource(this, R.raw.ferret)
.build().thenAccept(renderable -> ferretRenderable = renderable)
.exceptionally(
throwable -> {
Toast.makeText(this, "Unnable to load ferret model", Toast.LENGTH_SHORT).show();
return null;
}
);
ModelRenderable.builder()
.setSource(this, R.raw.hippopotamus)
.build().thenAccept(renderable -> hippopotamusRenderable = renderable)
.exceptionally(
throwable -> {
Toast.makeText(this, "Unnable to load hippopotamus model", Toast.LENGTH_SHORT).show();
return null;
}
);
ModelRenderable.builder()
.setSource(this, R.raw.horse)
.build().thenAccept(renderable -> horseRenderable = renderable)
.exceptionally(
throwable -> {
Toast.makeText(this, "Unnable to load horse model", Toast.LENGTH_SHORT).show();
return null;
}
);
ModelRenderable.builder()
.setSource(this, R.raw.koala_bear)
.build().thenAccept(renderable -> koalaRenderable = renderable)
.exceptionally(
throwable -> {
Toast.makeText(this, "Unnable to load koala model", Toast.LENGTH_SHORT).show();
return null;
}
);
ModelRenderable.builder()
.setSource(this, R.raw.lion)
.build().thenAccept(renderable -> lionRenderable = renderable)
.exceptionally(
throwable -> {
Toast.makeText(this, "Unnable to load lion model", Toast.LENGTH_SHORT).show();
return null;
}
);
ModelRenderable.builder()
.setSource(this, R.raw.reindeer)
.build().thenAccept(renderable -> reindeerRenderable = renderable)
.exceptionally(
throwable -> {
Toast.makeText(this, "Unnable to load reindeer model", Toast.LENGTH_SHORT).show();
return null;
}
);
ModelRenderable.builder()
.setSource(this, R.raw.wolverine)
.build().thenAccept(renderable -> wolverineRenderable = renderable)
.exceptionally(
throwable -> {
Toast.makeText(this, "Unnable to load wolverine model", Toast.LENGTH_SHORT).show();
return null;
}
);
}
private void createModel(AnchorNode anchorNode, int selected) {
if (selected == 1) {
TransformableNode bear = new TransformableNode(arFragment.getTransformationSystem());
bear.setParent(anchorNode);
bear.setRenderable(bearRenderable);
bear.select();
addName(anchorNode,bear,"Bear");
}
if (selected == 2) {
TransformableNode bear = new TransformableNode(arFragment.getTransformationSystem());
bear.setParent(anchorNode);
bear.setRenderable(catRenderable);
bear.select();
addName(anchorNode,bear,"Cat");
}
if (selected == 3) {
TransformableNode bear = new TransformableNode(arFragment.getTransformationSystem());
bear.setParent(anchorNode);
bear.setRenderable(cowRenderable);
bear.select();
addName(anchorNode,bear,"Cow");
}
if (selected == 4) {
TransformableNode bear = new TransformableNode(arFragment.getTransformationSystem());
bear.setParent(anchorNode);
bear.setRenderable(dogRenderable);
bear.select();
addName(anchorNode,bear,"Dog");
}
if (selected == 5) {
TransformableNode bear = new TransformableNode(arFragment.getTransformationSystem());
bear.setParent(anchorNode);
bear.setRenderable(elephantRenderable);
bear.select();
addName(anchorNode,bear,"Elephant");
}
if (selected == 6) {
TransformableNode bear = new TransformableNode(arFragment.getTransformationSystem());
bear.setParent(anchorNode);
bear.setRenderable(ferretRenderable);
bear.select();
addName(anchorNode,bear,"Ferret");
}
if (selected == 7) {
TransformableNode bear = new TransformableNode(arFragment.getTransformationSystem());
bear.setParent(anchorNode);
bear.setRenderable(hippopotamusRenderable);
bear.select();
addName(anchorNode,bear,"Hippopotamus");
}
if (selected == 8) {
TransformableNode bear = new TransformableNode(arFragment.getTransformationSystem());
bear.setParent(anchorNode);
bear.setRenderable(horseRenderable);
bear.select();
addName(anchorNode,bear,"Horse");
}
if (selected == 9) {
TransformableNode bear = new TransformableNode(arFragment.getTransformationSystem());
bear.setParent(anchorNode);
bear.setRenderable(koalaRenderable);
bear.select();
addName(anchorNode,bear,"Koala");
}
if (selected == 10) {
TransformableNode bear = new TransformableNode(arFragment.getTransformationSystem());
bear.setParent(anchorNode);
bear.setRenderable(lionRenderable);
bear.select();
addName(anchorNode,bear,"Lion");
}
if (selected == 11) {
TransformableNode bear = new TransformableNode(arFragment.getTransformationSystem());
bear.setParent(anchorNode);
bear.setRenderable(reindeerRenderable);
bear.select();
addName(anchorNode,bear,"Reindeer");
}
if (selected == 12) {
TransformableNode bear = new TransformableNode(arFragment.getTransformationSystem());
bear.setParent(anchorNode);
bear.setRenderable(wolverineRenderable);
bear.select();
addName(anchorNode,bear,"Wolverine");
}
}
private void addName(AnchorNode anchorNode, TransformableNode model, String name) {
ViewRenderable.builder().setView(this,R.layout.name_animal)
.build()
.thenAccept(viewRenderable -> {
TransformableNode nameView = new TransformableNode(arFragment.getTransformationSystem());
nameView.setLocalPosition(new Vector3(0f,model.getLocalPosition().y+0.5f,0));
nameView.setParent(anchorNode);
nameView.setRenderable(viewRenderable);
nameView.select();
//text
TextView txt_name = (TextView)viewRenderable.getView();
txt_name.setText(name);
//click to remove animal
txt_name.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
anchorNode.setParent(null);
}
});
}); }
private void SetClickListener() {
for (int i = 0; i < arrayView.length; i++) {
if (arrayView[i] != null)
arrayView[i].setOnClickListener(this);
}
}
private void SetArrayView() {
arrayView = new View[]{ bear,cat,cow,dog,elephant,ferret,hippopotamus,horse,koala,lion,reindeer,wolverine
};
}
@Override
public void onClick(View view) {
if (view.getId()== R.id.bear) {
selected = 1;
setBackground(view.getId());
}
else if (view.getId()==R.id.cat) {
selected = 2;
setBackground(view.getId());
}
else if (view.getId()==R.id.cow) {
selected = 3;
setBackground(view.getId());
}
else if (view.getId()==R.id.dog) {
selected = 4;
setBackground(view.getId());
}
else if (view.getId()==R.id.elephant) {
selected = 5;
setBackground(view.getId());
}
else if (view.getId()==R.id.ferret) {
selected = 6;
setBackground(view.getId());
}
else if (view.getId()==R.id.hippopotamus) {
selected = 7;
setBackground(view.getId());
}
else if (view.getId()==R.id.horse) {
selected =8;
setBackground(view.getId());
}
else if (view.getId()==R.id.koala) {
selected = 9;
setBackground(view.getId());
}
else if (view.getId()==R.id.lion) {
selected = 10;
setBackground(view.getId());
}
else if (view.getId()==R.id.reindeer) {
selected = 11;
setBackground(view.getId());
}
else if (view.getId()==R.id.wolverine) {
selected =12;
setBackground(view.getId());
}
}
private void setBackground(int id) {
for (int i =0;i<arrayView.length;i++){
if (arrayView[i].getId() == id)
arrayView[i].setBackgroundColor(Color.parseColor("#80333639"));
else
arrayView[i].setBackgroundColor(Color.TRANSPARENT);
}
}}
这是模特
public function index()
{
$this->load->view('view_demo');
}
public function search($id)
{
$id = $this->input->get('id');
$data['id'] = $this->datacomplete->information($id);
$this->load->view('view_demo', $id);
}
这是视图
public function information($id)
{
$q = $this->db->select('*')->from('autocomplete')->where('id', $id)->get();
return $q->result();
}
我有一个索引函数和view_demo页面,当我在搜索栏中搜索表单国家/地区名称(例如印度),然后提交搜索栏时,会出现一个搜索栏,然后将我重定向到<body style="background-color: #000000;">
<?php echo $id; ?>
<form action="<?php echo base_url('autocomplete/search/' .$id); ?>" method="get">
<div class="row">
<center>
<h2 style="color: #fff;">AUTOCOMPLETE FORM FROM DATABASE USING CODEIGNITER AND AJAX</h2>
</center>
<div class="col-md-4 col-md-offset-4" style="margin-top: 200px;">
<label class="control-lable" style="color: #fff;">Country Name</label>
<input style="height:70px" type="text" id="country" autocomplete="off" name="country" class="form-control" placeholder="Type to get an Ajax call of Countries">
<ul class="dropdown-menu txtcountry" style="margin-left:15px;margin-right:0px;" role="menu" aria-labelledby="dropdownMenu" id="DropdownCountry"></ul>
<button location.href='<?php echo site_url().'/autocomplete/search?id='.$id;?>' type="submit">Submit</button>
</div>
</div>
</form>
</body>
,并在url中得到国家/地区ID。
例如: http://localhost/codeajax/Autocomplete/search?id=233: 这里的233是印度的国家/地区ID。
我必须在搜索页面的URL中动态进行此操作。
这里搜索页面现在是空白页面,另外我还想在搜索页面上显示国家/地区ID。即空白页上的233。
答案 0 :(得分:0)
控制器
public function index()
{
$this->load->view('view_demo');
}
public function search($id)
{
$id = $this->input->get('id');
$data['id'] = $this->datacomplete->information($id);
$this->load->view('view_demo', $data);
}
模型
public function information($id)
{
$q = $this->db->select('*')->from('autocomplete')->where('id', $id)->get();
return $q->result();
}
查看
<body style="background-color: #000000;">
<?php echo $id; ?>
<form action="<?php echo base_url('autocomplete/search/' .$id); ?>" method="get">
<div class="row">
<center>
<h2 style="color: #fff;">AUTOCOMPLETE FORM FROM DATABASE USING CODEIGNITER AND AJAX</h2>
</center>
<div class="col-md-4 col-md-offset-4" style="margin-top: 200px;">
<label class="control-lable" style="color: #fff;">Country Name</label>
<input style="height:70px" type="text" id="country" autocomplete="off" name="country" class="form-control" placeholder="Type to get an Ajax call of Countries">
<ul class="dropdown-menu txtcountry" style="margin-left:15px;margin-right:0px;" role="menu" aria-labelledby="dropdownMenu" id="DropdownCountry"></ul>
<button location.href='<?php echo site_url().'/autocomplete/search?id='.$id;?>' type="submit">Submit</button>
</div>
</div>
</form>
</body>